zishu's blog

zishu's blog

一个热爱生活的博主。https://zishu.me

Add data to Vue arrays using this.$set.

Vue does not allow dynamically adding new root-level reactive properties to an already created instance. It can use the Vue.set(object, key, value) method to add reactive properties to nested objects.

If objects are directly added to an array, the view will not update, but the correct values can be output; only by using this.$set can the view be updated.

 for (let i = 0; i < this.data.length; i++) {
  // this.data[i].state = false;
  this.$set(this.data[i], 'state', false)
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.