Vue之for循环
来源:互联网 发布:centos修改ip地址 编辑:程序博客网 时间:2024/06/10 10:47
Vue中for循环的用法总结如下:
1.基本用法 v-for
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <style> </style> <script src="vue.js"></script> <script> window.onload=function(){ new Vue({ el:'#box', data:{ arr:['apple','banana','orange','pear'] } }); }; </script></head><body> <div id="box"> <ul> <li v-for="value in arr"> {{value}} </li> </ul> </div></body></html>
结果:
2.带索引的用法
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <style> </style> <script src="vue.js"></script> <script> window.onload=function(){ new Vue({ el:'#box', data:{ arr:['apple','banana','orange','pear'] } }); }; </script></head><body> <div id="box"> <ul> <li v-for="value in arr"> {{value}} {{$index}} </li> </ul> </div></body></html>
描述:
使用{{$index}}可以提供索引
结果:
3.使用(k,y) in arr
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>智能社——http://www.zhinengshe.com</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <style> </style> <script src="vue.js"></script> <script> window.onload=function(){ new Vue({ el:'#box', data:{ arr:['apple','banana','orange','pear'], json:{a:'apple',b:'banana',c:'orange'} } }); }; </script></head><body> <div id="box"> <ul> <li v-for="value in arr"> {{value}} {{$index}} </li> </ul> <hr> <ul> <li v-for="value in json"> {{value}} {{$index}} {{$key}} </li> </ul> <hr> <ul> <li v-for="(k,v) in json"> {{k}} {{v}} {{$index}} {{$key}} </li> </ul> </div></body></html>
描述:
{{k,v}} in arr k代表key, v代表value
结果:
阅读全文
1 0
- Vue之for循环
- vue-cli for循环
- vue v-for 循环对象
- Vue.js学习笔记:v-for循环
- vue规定v-for循环的次数
- 学习vue的弯弯绕绕之v-for循环输出图片
- vue.js之v-for
- Linux for循环之列表for循环
- bat之for循环
- bat之for循环
- bat之for循环
- bat之for循环
- bat之for循环
- bat之for循环
- shell之for循环
- Scala之for循环
- bash 之for循环
- shell 之 for 循环
- Leetcode 152-MaximumProductSubarray 解题报告
- UVa1630 Folding 记忆化搜索
- 何为语法糖?
- 问题:浏览器CSS/JS以怪异模式渲染
- D. Clique Problem
- Vue之for循环
- HTC按键代码
- mysql cpu使用率过高解决方法
- 资源链接
- heap和stack有什么区别
- 随笔
- final, finally, finalize的区别。
- 哈希表
- first week of machine learning on Coursera