v-for="循环元素 in 数组名" (不含下标的写法)
v-for="(循环元素,数组下标) in 数组名" (带上下标的写法)
2.1 普通数组
2.1.1 示例代码
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>普通数组循环展示数据</title><scriptsrc="../js/vue.js"></script></head><body><divid="app"><h3>普通数组循环</h3><ul><!-- 循环变量(元素) in 数组名 --><liv-for="g in games">{{g}}</li></ul></div><script>var v=newVue({el:'#app',data:{games:['英雄联盟','王者荣耀','梦幻西游']}})</script></body></html>
2.1.2 运行截图
2.2 json对象数组
2.2.1 示例代码
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>json数组循环演示</title><scriptsrc="../js/vue.js"></script></head><body><divid="app"><h3>json数组循环</h3><tableborder="1"><tr><th>序号</th><th>编号</th><th>商品名</th></tr><!-- (循环变量,数组下标) in 数组名 --><!-- sp是商品 s接收每个对象 i是坐标 从0开始--><trv-for="(p,i) in product"><th>{{i+1}}</th><th>{{p.id}}</th><th>{{p.name}}</th></tr></table></div><script>var v=newVue({el:'#app',data:{product:[{id:'10',name:'电脑'},{id:'20',name:'鼠标'},{id:'30',name:'键盘'},]},})</script></body></html>