On March 15, 2020, “One question of the Day series 🚀” by Wang Ergou blog: Dig gold, think not, Zhihu, Jane book, CSDN like again, form a habit, one question of the day series will be updated all the time, your support is the biggest motivation for me to continue to share 😘
How to track change
When you pass an ordinary JavaScript Object to a Vue instance as the data option, Vue iterates through all of the Object’s properties and converts them into getters/setters using Object.defineProperty.
When a page uses or modifs a property, dependency collection (collecting the watcher of the current component) is first performed. If the property changes, dependencies are notified to update (publish subscribe).
Responsive data
Restricted by modern JavaScript, Vue cannot detect the addition or deletion of object attributes.
Since Vue performs getter/setter conversions on the property when it initializes the instance, the property must exist on the data object for Vue to convert it to reactive.
Vue.set this.$set
Vue cannot detect the addition or deletion of object attributes. The solution is to manually call Vue. Set or this.$set.
Tell yourself that even if you are tired, don’t forget to learn. There is no shortcut to success, only step by step. ‘!
If there is something wrong in the article, you are welcome to correct it.
Thank you ~ 💘