Which operations in vue2 are not responsive (the data has changed, the view has not been updated)

what circumstances

The new attributes of the object are not responsive (there is an object, the object has a name and age, and I will add xxx later) The key assignment of the object is added later

Deletion is not responsive, delete a property in the object

Some operations on the array are not responsive. Modify the array content through the index

reason :

Subsequent key assignment of the object, because vue2 uses Object.defineProperty to recursively hijack each attribute, if these attributes are added later, they will not be hijacked

Modify the content of the array through the index, Object.defineProperty supports the hijacking of the array, the author did not do this for performance reasons

Solution : this.$set, or vue.set delete solution this.$delete

Vue3 will not have these problems, proxy will proxy the entire object, it does not matter whether this property is added later, and there is no performance problem for arrays

 

Guess you like

Origin blog.csdn.net/Qiemo_/article/details/125827484