What happens when n is used instead of defined in data?

  • Vue will give a warning
  • If there is a second level attribute, there is no warning, and Vue only checks the first level attribute

Object.defineProperty(obj,’n’,{… }) there must be an ‘n’ in order for the VM to listen on &proxy obj.n. Vue cannot listen on n, which is not there in the first place

How to solve it?

  1. Set /this.$set to add a key
  2. It is better to write the attribute in advance and set the value to undefined without adding a key

Vue.set/this.$set

  • The new key
  • Proxies and listeners are created automatically if they have not been created
  • Trigger UI update (note not immediately)
  • Vue.set(this.object,’n’,1) / this.set(this.object,’n’,1)

$set /this.$set/Vue. $set /this.$set/Vue.

The new key in the array

  • Common operations on array lengths are push, pop,,
  • This can be solved by tampering with these apis
  • The tampered API automatically handles listeners and proxies and updates the UI
  • Vue provides seven tampered apis for adding and deleting arrays