Constantin Druccdruc

Hey, I'm Constantin Druc!

I'm a web developer sharing everything I know about building web applications.

I'm making a course on Laravel Sanctum: MasteringAuth.com

Vue 3 - watch multiple values

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)
);
Tags: