Talking about Vue's instance methods vm.$set(), vm.$set(), vm.$delete()

vm.$set

  • Function: Add an attribute to the responsive object, and ensure that this new attribute is also responsive, and trigger a view update. It must be used to add new properties to reactive objects, because vue cannot detect ordinary new properties (such as this.myObject.newProperty='hi'). Note: The object cannot be a vue instance, or a data object of a vue instance
  • Location: Vue.set() global-api/index.js
  • vm.$set() instance/index.js
  • set() method observer/index.js

vm.$delete

  • Function: Delete the properties of the object. If the object is responsive, make sure that the deletion can trigger an update of the view. This method is mainly used to avoid the restriction that Vue cannot detect that the attribute is deleted.
  • Note: The target object cannot be a vue instance or the root data object of a vue instance.
  • Definition location: Vue.delete() global-api/index.js
  • vm.$delete() instance/index.js
  • Source code: src\core\observer\index.js

vm.$watch(expOrFn,callback,[options])

  • Function: an expression or calculation property function to observe the changes of the vue instance. The parameters obtained by the callback function are the new value and the old value. The expression only accepts supervised key paths. For more complex expressions, use a function instead.
  • Parameter
    expOrFn: the attribute in $data to be monitored, which can be an expression or function
    callback: a callback function executed after the data changes, the object has a handler attribute (string or function), if the attribute is a string, the corresponding method in methods definition.
    options: deep Boolean deep monitoring, immediate Boolean whether to execute the callback function immediately

Guess you like

Origin blog.csdn.net/weixin_40599109/article/details/108399753