Skip to content

Commit

Permalink
Vue双向绑定原理
Browse files Browse the repository at this point in the history
  • Loading branch information
yzsunlei committed Dec 17, 2019
1 parent d31e37a commit fc18b05
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
我们来简单理一下实现思路:

> 1、input输入框以及div文本和data中的数据进行绑定
> 2、input输入框内容变化时,data中的对应数据同步变化,即 view => model
> 3、data中数据变化时,对应的div文本内容同步变化,即 model => view
## 原理介绍
Expand Down Expand Up @@ -135,7 +137,9 @@ function Dep() {
简单解析如下:

> 1、实现一个数据监听器Obverser,对data中的数据进行监听,若有变化,通知相应的订阅者。
> 2、实现一个指令解析器Compile,对于每个元素上的指令进行解析,根据指令替换数据,更新视图。
> 3、实现一个Watcher,用来连接Obverser和Compile, 并为每个属性绑定相应的订阅者,当数据发生变化时,执行相应的回调函数,从而更新视图。
### Vue中的Observer:
Expand Down

0 comments on commit fc18b05

Please sign in to comment.