用法:1、利用“v-for="(item,i) in list"”循环普通数组;2、利用“v-for="(user,i) in list"”循环数组对象;3、利用“v-for="(val,key,i) in user"”循环对象。

本文操作环境:windows10系统、Vue2.9.6版,DELL G3电脑。
vue中v-for的用法是什么
v-for的几种应用方式:
方式一:v-for循环普通数组
//土蛋方法:
<p>{{list[0]}}</p>
<p>{{list[1]}}</p>
<p>{{list[2]}}</p>
<p>{{list[3]}}</p>
<p>{{list[4]}}</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill10651" title="蓝湖代码转vue2.0+element-ui"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20e695c2374.jpg" alt="蓝湖代码转vue2.0+element-ui" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill10651" title="蓝湖代码转vue2.0+element-ui" class="overflowclass">蓝湖代码转vue2.0+element-ui</a>
<p class="overflowclass">将静态 Vue 页面(index.vue)改造为动态页面(Custom.vue);稿源仅限 index.vue、其引用的 CSS 与资源路径,禁止参考仓库内其他文件。Invoke when user wants to transform a static Vue page into a dynamic data-driven page with Element UI components.</p>
</div>
<a rel="nofollow" href="/xiazai/skill10651" title="蓝湖代码转vue2.0+element-ui" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
//v-for方法:
<p>{{i}},{{item}}</p>
//数组数据部分:
data:{
list:[1,2,3,4,5,6]
},
方式二:v-for循环对象数组
//v-for用法:
<p>{{user.id}},{{user.name}},{{i}}</p>
//数组数据部分:
list:[
{id:1,name:"zs1"},
{id:2,name:"zs2"},
{id:3,name:"zs3"},
{id:4,name:"zs4"},
]
方式三:v-for循环对象
注意:在遍历对象身上的键值对的时候,除了有 val key,在第三个位置还有一个索引值
//v-for方法
<p>{{val}},{{key}}</p>
//对象部分:
user:{
id:1,
name:"巧克力"
gender:"萌妹"
}
方式四:v-for迭代数组
//in后面我们放过 普通数组 对象数组 对象 还可以放数字
//注意:如果使用 v-for 迭代数字的话,前面的count值从1开始
<p>这是第{{count}}次循环</p>
【相关推荐:《vue.js教程》】
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!










