Watcher doesn’t support lambda functions in Vue

The reason that you can’t execute the following code

watch: {     
a: (val, oldVal) => {
this.executeMyMethod()
}
}

is because arrow functions bind to the parent context, so ‘this’ will not be the vue context as you expect, this.executeMyMethod will be undefined.

This is how your code should look like:

watch: {     
a: function(val, oldVal){
this.executeMyMethod()
}
}

Enjoy!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store