Vue Watch Multiple Values

Posted on  by admin

Modified8 months ago. Currently I have to watch a few properties. And if each of them changes, I have to invoke the same function:. So I am having to write the same code multiple times above.Is it possible to simply have all properties being watched and invoke their change handler without having to write same code multiple times?

  1. PS: I am using vue 1.x. 1515 bronze badges. 9,1451818 gold badges8383 silver badges146146 bronze badges.
  2. 8383 silver badges146146 bronze badges. Update: April-2020. For people who are using Vue 3, the watch API can accept multiple sources.

Original answer for Vue 2.

there is no official way to solve your question(see this). but you can use the computed property as a trick:. if you just want to do something and don't care about what's new/old values.ignore two lines.

11 gold badge2424 silver badges2626 bronze badges. 2626 bronze badges. Another possibility:. More info on the Vue API docs for vm.$watch. 3535 gold badges316316 silver badges291291 bronze badges. 291291 bronze badges.