[Vuejs]-Vue2 – update object same way as delete

4πŸ‘

βœ…

Yes with Vue.set. However, it’s only needed when adding a new property to an object, not when updating an already reactive property.

See https://v2.vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats for more information:

Change Detection Caveats

Due to the limitations of modern JavaScript (and the abandonment of
Object.observe), Vue cannot detect property addition or deletion.
Since Vue performs the getter/setter conversion process during
instance initialization, a property must be present in the data object
in order for Vue to convert it and make it reactive.

Vue does not allow dynamically adding new root-level reactive
properties to an already created instance. However, it’s possible to
add reactive properties to a nested object using the Vue.set(object, key, value) method.

πŸ‘€thibautg

Leave a comment