一、基础
1、v-for用来展示列表数据
2、语法 v-for="(value, index) in xx" :key="index"
3、可遍历:数组、对象、字符串
注意:先是值,再是索引
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>列表渲染-基础</title> <script type="text/javascript" src="../js/vue.js"></script> </head> <body> <div id="container"> <h2>人员信息</h2> <ul> <li v-for="(p, index) in personArr" ::key="p.id"> {{p.name}}-{{p.age}}--{{index}} </li> </ul> <h2>遍历对象</h2> <ul> <li v-for="(value, key, index) in personObj" :key="index"> {{index}}-{{key}}-{{value}} </li> </ul> </div> <script> new Vue({ el:"#container", data:{ // 遍历数组 personArr:[ {id:"01", name:"张三", age:"40"}, {id:"02", name:"李四", age:"41"}, {id:"03", name:"王五", age:"42"}, ], //遍历对象 personObj:{ name:"王二麻子", age:40, sex:"男" } } }) </script> </body> </html>
标签:index,Vue,name,渲染,age,列表,遍历,id From: https://www.cnblogs.com/wt7018/p/18642433