vue 使用v-for遍历数组和遍历对象
v-for遍历数组
name:,
age:
删除
更新
v-for遍历对象1
v-for遍历对象2
:
var v=new Vue({
el:'#app',
data:{
student:[
{name:'wag',age:1},
{name:'wag1',age:2},
{name:'wag2',age:23},
{name:'wag3',age:44}
],
teacher:{
name:'jiajia',
age:23,
className:'语文'
}
},
methods:{
//删除
del(index){
this.student.splice(index,1);
},
//更新
update(index,stu){
//this.student[index]=stu;//并没有改变stu本身,所以页面上不会发生变化
/**
* 以下方法被vue包装,使用以下方法将会触发视图的更新
push()
pop()
shift()
unshift()
splice()
sort()
reverse()
**/
this.student.splice(index,1,stu);
}
}
})