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