-
1,
initData
execution: bygetData
calling the functionvm.$options.data
to get data objects option, and do the type of incoming processing,data
andmethod
passed in the same name do warning. Priority relationship:props
Priority>methods
Priority>data
Priority -
2, call the
observe
function todata
convert the data objects responsive to -
3,
observe(data, true /* asRootData */)
the data observed conditions were required, in line with the conditions will be monitored -
4, watch what can monitor
data
: dependentObject.defineProperty
function, by which the object function for each attribute a pair of getter / setter so that attribute is read and is set,$watch(render,render)
perform the firstrender
execution, the triggerget
blocker, dependent collection, the secondrender
when dependent changes performed, and changes to the applicationDOM
-
5,
Observer(value、dep 、 vmCount、walk 和 observeArray)
class takes one parameter, i.e. the data object, the function, theget
function is mainly completed two important part of the work, a correct attribute value is returned, and the other is dependent collection.set
Function also complete two important things, the first correctly set new values for the attribute, and the second is capable of triggering a respective dependency, responsive to resolve the data inconsistency -
6, it is determined
vm.$options.render
whether or not true, back into thecallHook(vm, 'beforeMount')
function,updateComponent
function to render the generated virtual functionDOM
rendered into a realDOM
,updateComponent
asWatcher
the second parameter.Watcher
Examples of the observer willupdateComponent
function evaluation,updateComponent
execution of the function indirectly triggers the rendering function (vm.$options.render
execution), so that the trigger data attributeget
interceptor function, so that the dependence (observer) to collect, when the data changes will execute theupdateComponent
function, which to complete the re-rendering -
7, the observer repetitive processing done to avoid repetition, make
try
,catch
handle to clear the error location -
8, when the update data occurs,
queueWatcher
a function of the observer will be unified into a queue waiting to perform the update (repeated optimization queues do) after completion of all mutants
vue source code analysis of two-way data binding model mvvm
Guess you like
Origin blog.csdn.net/weixin_42204698/article/details/91494854
Recommended
Ranking