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

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

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

 

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

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

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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM