1,示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<div v-for="(item,index) of list" :key="item.id">
{{item.id}}
</div>
<div v-for="(item,key,index) of userInfo">
{{item}} --- {{key}} ---{{index}}
</div>
</div>
<script>
//Vue.set(app.list,1,{id:'003',name:'hhhh'})
//app.$set(app.list,0,{id:'004',name:'ahshhs'})
//Vue.set(app.userInfo,'sex','男')
//app.$set(app.userInfo,'phone','12345678')
var app=new Vue({
el:"#app",
data:{
content:'hello vue',
list:[{
id:"001",
name:'zhangsan'
},{
id:'002',
name:'lisi'
}],
userInfo:{
id:'123',
name:'zhangsnah',
age:29,
address:'shanghai'
}
}
})
</script>
</body>
</html>
|
2,在控制台输入
Vue.set(app.list,1,{id:'003',name:'hhhh'})
//app.$set(app.list,0,{id:'004',name:'ahshhs'})
Vue.set(app.userInfo,'sex','男')
//app.$set(app.userInfo,'phone','12345678')
页面会及时更新
3,操作数组有7中方法
push pop shift unshift splice sort reverse