列表渲染
创建 06-列表渲染.html
v-for:列表循环指令
例1:简单的列表渲染
<!-- 1、简单的列表渲染 -->
<ul><li v-for="n in 10">{{ n }} </li>
</ul>
<ul><!-- 如果想获取索引,则使用index关键字,注意,圆括号中的index必须放在后面 --><li v-for="(n, index) in 5">{{ n }} - {{ index }} </li>
</ul>
例2:遍历数据列表
data: {userList: [{ id: 1, username: 'helen', age: 18 },{ id: 2, username: 'peter', age: 28 },{ id: 3, username: 'andy', age: 38 }]
}
<!-- 2、遍历数据列表 -->
<table border="1"><!-- <tr v-for="item in userList"></tr> --><tr v-for="(item, index) in userList"><td>{{index}}</td><td>{{item.id}}</td><td>{{item.username}}</td><td>{{item.age}}</td></tr>
</table>