VUE中不能使用箭头函数的地方

1.不应该使用箭头函数来定义一个生命周期方法

2.不应该使用箭头函数来定义 method 函数

3.不应该使用箭头函数来定义计算属性函数

4.不应该对 data 属性使用箭头函数

5.不应该使用箭头函数来定义 watcher 函数

原因:

箭头函数绑定了父级作用域的上下文,this 将不会按照期望指向 Vue 实例。

也就是说,你不能使用this来访问你组件中的data数据以及method方法了。

this将会指向undefined。经常导致 Uncaught TypeError: Cannot read property of undefinedUncaught TypeError: this.myMethod is not a function 之类的错误