VueJS – watch multiple values

So recently, I had a situation in Vue that involved watching multiple values and then acting based on their changes.

Here’s how you can do it:

watch(
  () => [form.available_in_stores, form.available_online],
  ([availableInStores, availableOnline]) => {
    if (!availableInStores && !availableOnline) {
      form.is_sellable = false;
    }
  }
);

However, at least for the example above, you can also combine the watched values:

watch(
  () => form.available_in_stores || form.available_online,
  isSellable => (form.is_sellable = isSellable)
);

Leave a Reply