vm.$set( target, key, value ) target:要修改的目标值;key:修改的索引;value :修改的值
data: {
items: [{ name: 'xiao1' }, { name: 'xiao2' }, { name: 'xiao3' }] },
methods: {
test() {
this.$set(this.items,2,{name: 'xiao4!'})
}
}
例子
data(){
dataList:[]
}
......
var data=[]
data.foreach(item,index){
if(item.id==2){
this.$set(this.dataList,index,item)
}
网友评论