Since Vue does not allow you to dynamically add root-level responsive properties, you must declare all root-level responsive properties, even if they are null, before initializing the instance:
The object.defineProperty () method directly defines a new property on an Object, or modifies an existing property of an Object, and returns the Object. Through getter and setter functions
Manipulating data or objects directly through assignment,property is not reactive,
vm= new Vue({mydata})
Copy the code
1. Vm makes a layer proxy for data. For vm.n, it is equivalent to mydata.n. All properties of MyData are monitored. Why monitor, in case the properties of myData change and the VM doesn’t know what the VM knows? The render(data) function is called.
Go to Github, go to the 2.6 branch, go to the instance file in the SRC file, and the core file declares the vue function and initializes options. State is initialized, data pairs written with underscore data are stored, and the passed state is a layer of proxy. Raw data can be accessed through proxies. Vue hijacks getters and setters of Object properties via object.defineProperty to notify when data changes
vue.set()
Vue cannot detect array and object changes. To solve this problem, Vue.$set()Copy the code
Asynchronous update queues use vue.nexttick () asynchronous execution to update DOM operations in vUE using native Promise.then, MutationObserver, and setImmediate. SetTimeout (fn, 0)