Usage: 1. Use "v-for="(item,i) in list"" to loop through ordinary arrays; 2. Use "v-for="(user,i) in list"" to loop through arrays Object; 3. Use "v-for="(val,key,i) in user"" to loop the object.
The operating environment of this article: Windows 10 system, Vue version 2.9.6, DELL G3 computer.
Several application methods of v-for:
//土蛋方法: <p>{{list[0]}}</p> <p>{{list[1]}}</p> <p>{{list[2]}}</p> <p>{{list[3]}}</p> <p>{{list[4]}}</p> //v-for方法: <p v-for="(item,i) in list">{{i}},{{item}}</p> //数组数据部分: data:{ list:[1,2,3,4,5,6] },
//v-for用法: <p v-for="(user,i) in list">{{user.id}},{{user.name}},{{i}}</p> //数组数据部分: list:[ {id:1,name:"zs1"}, {id:2,name:"zs2"}, {id:3,name:"zs3"}, {id:4,name:"zs4"}, ]
Note: When traversing the key-value pairs on the object, in addition to the val key, there is an index value in the third position
//v-for方法 <p v-for="(val,key,i) in user">{{val}},{{key}}</p> //对象部分: user:{ id:1, name:"巧克力" gender:"萌妹" }
//in后面我们放过 普通数组 对象数组 对象 还可以放数字 //注意:如果使用 v-for 迭代数字的话,前面的count值从1开始 <p v-for="count in 10">这是第{{count}}次循环</p>
[Related recommendations: "vue.js tutorial"]
The above is the detailed content of What is the usage of v-for in vue. For more information, please follow other related articles on the PHP Chinese website!