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的更新。