Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VueJS | Method "watch" has type "object" in the component definition

Currently I have following Watches in Product.vue file

watch: {
    isOnline: {
      async handler (isOnline) {
        if (isOnline) {
          const maxQuantity = await this.getQuantity();
          this.maxQuantity = maxQuantity;
        }
      }
    },
    isMicrocartOpen: {
      async handler (isOpen) {
        if (isOpen) {
          const maxQuantity = await this.getQuantity();
          this.maxQuantity = maxQuantity;
        }
      },
      immediate: true
    },
    isSample (curr, old) {
      if (curr !== old) {
        if (!curr) {
          console.log('send the updateCall', curr);
          // this.updateProductQty(this.product.qty);
          pullCartSync(this);
        }
      }
    }
  }

but I am getting this following error (Vue Warn) in console

[Vue warn]: Method "watch" has type "object" in the component definition. Did you reference the function correctly?

enter image description here

I'm not sure why i am getting this error, as the syntax i am using seems to be correct, and its even functioning right.

Any suggestions why its giving this warning in error console?


Update:

Location where i have used the watch in vue page.

enter image description here

like image 782
Sizzling Code Avatar asked Dec 15 '20 07:12

Sizzling Code


People also ask

What does watch do in VUE JS?

The Vue. js Watcher or watch property allows the developers to listen to the component data and run whenever they change a particular property. The watcher or watch property is a unique Vue. js feature that lets you keep an eye on one property of the component state and run a function when that property value changes.

What is $El in Vuejs?

The $el option in Vue provides Vue with an existing HTML element to mount the Vue instance generated using the new keyword. this. $el. querySelector is used to access HTML elements and modify the element's properties.

How do I define a Vue component?

Vue components are written as a combination of JavaScript objects that manage the app's data and an HTML-based template syntax that maps to the underlying DOM structure.


Video Answer


1 Answers

You have something like methods: { watch: {} } in your component definition. That's why vue is complaining. That might be added by a mixin as well.

like image 149
Orkhan Alikhanov Avatar answered Sep 21 '22 00:09

Orkhan Alikhanov