Using the new syntax of ES6 in vue watch, I don't understand why it can be used in this way.

let vm = new Vue({
  el: "-sharpapp",
  data: {
    number: 0
  },
  methods: {
    res() {
      console.log("")
    }
  },
  watch: {
    number: ["res"]
  }
})

watchnumberES6[res],["res"]methodsres
Mar.18,2021

directly write [res] , js how do I know what this res refers to?

know that for js parsers, watch.number: [res] and methods.res are completely unrelated.

Vue cannot exceed the expressive power of js syntax, so the only way to write this monitor is that Vue will help you to find a corresponding function in methods .

Menu