当前位置:网站首页>2.4 circular statements
2.4 circular statements
2022-07-21 16:05:00 【Qwe7】
2.4 Loop statement
Vue The circular keyword in does not Java So many , Only v-for, But there are many uses . Next, let's introduce .
We need to define the data source , And then through v-for To traverse the data source , Then use the difference expression to output data .
a. Normal cycle
<body>
<div id="app">
<ul>
<li v-for="a in args">{{a}}</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
args:[1,2,3,4,5,6]
}
});
</script>
b. With an index for
<body>
<div id="app">
<ul>
<li v-for=" (a,i) in args" :key='i'>{{i}}{{a}}</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
args:[1,2,3,4,5,6]
}
});
</script>
c. Traversing objects
<body>
<div id="app">
<ul>
<li v-for="(v,k,i) in student">{{i+1}}--{{k}}--{{v}}</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
student:{
username:' Little fish ',
age:20,
girl:' Flowery '
}
}
});
</script>
v、k、i You can define these characters yourself , Respectively represent the value of each cycle content 、 key 、 Serial number .
- v: The value of each data in the loop Little fish 、20、 Flowery
- k: The key of daily data in the loop username、age、girl
- i: The serial number of the loop , from 0 Start
d. Traversing an array of objects
<body>
<div id="app">
<ul>
<li v-for=" student in students">
<span v-for="(v,k,i) in student">{{i+1}}--{{k}}--{{v}}</span>
</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
students:[
{
name:'xiaoming',
age:20
},
{
name:'xiaowang',
age:21
}
]
}
});
</script>
You can see it clearly , At this point, the data source is a student Array , Through two layers v-for loop , The outer layer traverses each... In the array student object , Inner layer v-for Iterate through the of each object v、k、i.
The page effect is as follows :
边栏推荐
- 【Star项目】小帽飞机大战(一)
- Realize joint testing through TPT fusion platform
- [stc15 controls ws2812 RGB color lamp cascade]
- 解决突然跳出命令行(闪烁)
- 阿里云国际版账户登录不上去什么原因?
- CentOS 7上集群化部署Apache Druid 0.22实时分析数据库
- Five reasons why developers use Klocwork for software security
- Is there any risk in opening a mobile stock account? Is it safe?
- What aspects should we start from to learn the silver K-line chart
- 漏洞扫码--需要整改的
猜你喜欢
Wechat vaccine reservation applet graduation design of applet completion work (3) background function
EasyGBS平台设置小技巧:如何隐藏平台web页面不被访问?
【Star项目】小帽飞机大战(一)
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of the asset!
[JS] event communication
-实体建模-
Using go TCP to realize simple online group chat function
Why does someone choose the one with high quotation in software development? Did they lose money?
Projection & local illumination
修改标注样式文字填充颜色
随机推荐
BluePrism工具菜单栏用户权限功能描述-RPA第二章
What if the download of Duoyu security browser is blocked? Turn off the method of download blocking
i2c adapter驱动
What are the methods to realize timeout in go language
【Flutter -- 实战】快速入门 Flutter
每日一题-LeetCode1260-二维网格迁移-数组-映射
【Example】在输入框内输入文本,输出打字机效果
[JS] event communication
2022/07/20 learning notes (Day12) string string string
[Star Project] small hat aircraft War (I)
小程序毕设作品之微信疫苗预约小程序毕业设计(5)任务书
c || 数组与指针
小程序毕设作品之微信疫苗预约小程序毕业设计(1)开发概要
Three structures of C language
Esp32-cam - intranet penetration tutorial
Because mongodb didn't get started, I lost an internship
Wechat vaccine appointment applet graduation project of applet completion work (4) opening report
conda虚拟环境默认路径如何修改
In depth analysis: how chain 2+1 mode plays with investment attraction and drainage
TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation