不要在选项属性或回调上使用箭头函数,比如 created: () => console.log(this.a)
或 vm.$watch('a', newValue => this.myMethod())。因为箭头函数并没有 this,
this会作为变量一直向上级词法作用域查找,直至找到为止,经常导致
Uncaught TypeError: Cannot read property of undefined 或
Uncaught TypeError: this.myMethod is not a function 之类的错误。
本文探讨了在Vue.js中使用箭头函数可能导致的问题,如'Uncaught TypeError: Cannot read property of undefined'错误,解释了原因在于箭头函数的this指向问题。
13万+

被折叠的 条评论
为什么被折叠?



