vue Watcher分类 computed watch

1、Watcher构造函数源码部分代码

    if (options) {
      this.deep = !!options.deep
      this.user = !!options.user
      this.lazy = !!options.lazy
      this.sync = !!options.sync
      this.before = options.before
    } else {
      this.deep = this.user = this.lazy = this.sync = false
    }

 

2、deep watcher

deep watcher指的是深度 watcher

watch: {
    // 深度 watcher
    c: {
      handler: function (val, oldVal) { /* ... */ },
      deep: true
    }
  }

可以深度监测对象属性的改变

 

3、user watcher

就是一般的vue的watch属性

https://cn.vuejs.org/v2/api/#watch

 

4、computed watcher

扫描二维码关注公众号,回复: 4188766 查看本文章

computed watcher指的是vue下的computed属性。

https://cn.vuejs.org/v2/api/#computed

 

总结:computed和watch都是基于Watcher实现的

https://cn.vuejs.org/v2/guide/computed.html

现在这个理解了吧,只有属性值变化,才触发watcher的更新

 

猜你喜欢

转载自www.cnblogs.com/mengfangui/p/10003402.html