遍历dom节点,找到正则匹配的{{}}所在节点,执行$watch方法。

$watch方法传入两个参数:
1.绑定的数据路径
2.回调函数
回调函数包含了对应的节点信息。

$watch方法的实现:
生成一个Watcher实例,用于收集依赖。
然后就把Watcher实例放入全局target。
依赖收集的方式是,访问object数据,从而触发get方法。
get方法里判断有全局的target,执行Dep实例的addDepend方法。
addDepend方法内容:全局target也就是Watcher实例执行addDep方法。
addDep方法内容:把Watcher实例放入Dep实例的数组中。
完成依赖收集。

参考:
https://github.com/muwoo/wue

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2023-04-03
  • 2021-08-15
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2022-02-15
  • 2022-12-23
  • 2018-11-28
相关资源
相似解决方案