[Vuejs]-Any difference between using this to access the watcher's value and using the argument?

3👍

this.myVar and value are the same in this case. The use of value is tiny bit more efficient because it doesn’t require to access this property again, and it’s shortened to one-letter variable in minified build. More importantly, it can be named for readability or brevity, and can be complemented with another parameter:

myVar(value, oldValue) {
  ...

In case a watcher is asynchronous, value captures the original value, while this.myVar contains the current value, which may be desirable or not depending on a case:

async myVar(value, oldValue) {
  ...
  console.log(this.myVar !== value);

Leave a comment