基本语法
v-for=“(item,index)in 数据”
v-for="(item ,index) in objArr" 可以选择属性
<!DOCTYPE html> <html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <!-- <input type="button" value="点击按钮可以打招呼" @click="cli">--> <ul> <li v-for="(item ,index) in arr" :title="item"> {{index+1}}{{item}} </li> </ul> <ul> <li v-for="(item ,index) in objArr" :title="item"> {{index+1}}{{item}} </li> </ul> <ul> <li v-for="(item ,index) in objArr" > {{item.age}} {{item.name}} </li> </ul> </div> </body> <!--vue开发环境配置,,,必须要有,没有就会无法运行vue--> <script src="http://cdn.jsdelivr.net/npm/vue/dist/vue.js"> </script> <script> var app1=new Vue({ el:"#app", data:{ arr:[1,2,3,4,5], objArr:[{name:"alex" ,age:53}, {name: "aife" ,age:28}] } }) </script> </html>