Vue 遍历对象
vue 遍历对象定义数组person:[{name:“jack”,age:19},{name:‘luvy’,age:18},{name:‘lucy’,age:17},{name:‘kka’,age:19},{name:‘lk’,age:19}]对数组person进行遍历用了两种方法第一种v-for=“iteam in person”相当于foreach遍历第二种...
·
vue 遍历对象 定义数组
person:[
{name:“jack”,age:19},
{name:‘luvy’,age:18},
{name:‘lucy’,age:17},
{name:‘kka’,age:19},
{name:‘lk’,age:19}
]
对数组person进行遍历用了两种方法
第一种 v-for=“iteam in person” 相当于foreach遍历
第二种方法 指定对象 用key value遍历
<div id="dali">
<h2>测试 v-for 遍历对象1</h2>
<ul>
<li v-for="iteam in person">
{{iteam.name}}--{{iteam.age}}
</li>
</ul>
<h2>测试 v-for 遍历对象2</h2>
<ul>
<li v-for="(value,key) in person[1]" v-bind:key="key">
{{key}}--{{value}}
</li>
</ul>
</div>
<script type="text/javascript">
var vue=new Vue({
el:"#dali",
data:{
person:[
{name:"jack",age:19},
{name:'luvy',age:18},
{name:'lucy',age:17},
{name:'kka',age:19},
{name:'lk',age:19}
]
}
})
</script>
效果如下:
更多推荐
已为社区贡献3条内容
所有评论(0)