I am learning Vue and facing a problem while using arrow function in computed property.
My original code works fine (See snippet below).
You are facing this error because an arrow function wouldn't bind this
to the vue instance for which you are defining the computed property. The same would happen if you were to define methods
using an arrow function.
Don’t use arrow functions on an instance property or callback (e.g.
vm.$watch('a', newVal => this.myMethod()))
. As arrow functions are bound to the parent context, this will not be the Vue instance as you’d expect andthis.myMethod
will be undefined.
You can read about it here.