解决vue修改数组数据,dom层未同步问题

vue2.0 给data对象、数组新增属性,并触发视图更新

使用方法

      this.$set(this.data,”key”,value’)

实例:

nowDevices:[ {id: '',name: ''} ]
this.$set(this.nowDevices,l,{id: id, name:name});//数组

 

student: { name: '', sex: '' }

this.$set(this.student,"age", 24)    //对象

附加一下删除的代码:

this.nowDevices.splice(i,1);//删除数组nowDevices下标为i的元素

你可能感兴趣的:(web)