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的元素