Notes mvvm principle

The basic principle of vue2.0 in MVVM

Construction ...

Implementation of two-way binding

angular used is dirty check the value of that difference contrast old and new values in the various events triggered.

vue is used in data hijacking , in conjunction with the publisher - subscriber mode, Object.defineProperty()to hijack each attribute getter/ setterpublish messages to subscribers when the data changes, the trigger monitor callback.

  1. Initialization, all data (the Data) , layer by layer recursively traverse a number of the same name became the setter / getter , then these properties made into its one to one listener (Watcher) , and stored in a subscription (Dep) object an array.
  2. By a compiler (the Compile) where the DOM tag data to be displayed, replacing the data (Data) the current value becomes html rendering a band data.
  3. Once the value change triggers a observers (Observer) object that to perform subscription (Dep) , stored in the plurality of object listener (Watcher) array, a watcher found to operate in line with the change value corresponding update method, by executing the compiler (compile) Furnished callback function in advance, rendering DOM again

Guess you like

Origin www.cnblogs.com/sirenvoid/p/12453016.html