vue.js(8)--v-for的使用
v-for遍历数组、对象数组、对象、迭代次数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>v-for遍历</title> <script src="../lib/vue.js"></script> </head> <body> <div class="app"> <p v-for="(i,item) in list">******索引值:{{ i }}***值:{{ item }}******</p> <!-- v-for遍历普通数组 --> <p v-for="(item,i) in arr">id:{{item.id}}********name:{{item.name}}*******索引值:{{i}}</p> <!-- v-for遍历数组中的对象 --> <p v-for="(val,key,i) in user">val:{{val}}****key:{{key}}******index:{{i}}</p> <!-- v-for直接遍历对象 --> <p v-for="i in 10">这是第{{i}}次循环</p> <!-- 遍历迭代次数 --> </div> <script> var vm = new Vue({ el:'.app', data:{ list:[0,1,2,3,4,5], arr:[ {'id':1,'name':'齐怪'}, {'id':1,'name':'齐怪'}, {'id':1,'name':'齐怪'}, ], user:{ 'id':'1', 'name':'齐怪', 'sex':'boy' } } }) </script> </body> </html>