在vue中数组的元素并不是响应式的,有时会出现数据改变而页面不响应的问题。
这里通过this.$set来让数组的元素变为响应式数据
例如我为对象数组noteList的每一个对象添加了一个为disabled的属性,并且让他变为响应式的数据,初始值为true
this.noteList.forEach((item) => {
this.$set(item, 'disabled', true);
});
在后面去修改这个disabled属性时,就会改变页面了。
在vue中数组的元素并不是响应式的,有时会出现数据改变而页面不响应的问题。
这里通过this.$set来让数组的元素变为响应式数据
例如我为对象数组noteList的每一个对象添加了一个为disabled的属性,并且让他变为响应式的数据,初始值为true
this.noteList.forEach((item) => {
this.$set(item, 'disabled', true);
});
在后面去修改这个disabled属性时,就会改变页面了。