vue報錯TypeError: Cannot read property of undefined 或 Uncaught TypeError: this.myMethod is not a function


不要在選項屬性或回調上使用箭頭函數

// 比如
created: () => console.log(this.a)
vm.$watch('a', newValue => this.myMethod())

因為箭頭函數並沒有 this,this會作為變量一直向上級詞法作用域查找,直至找到為止


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM