VueJS |方法“观看"具有类型“对象"在组件定义中 [英] VueJS | Method "watch" has type "object" in the component definition

查看:9
本文介绍了VueJS |方法“观看"具有类型“对象"在组件定义中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在 Product.vue 文件中有以下 Watches

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);
        }
      }
    }
  }

但我在控制台中收到以下错误(Vue Warn)

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

[Vue 警告]:方法观察";具有类型对象"在组件定义中.您是否正确引用了该函数?

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

我不知道为什么我会收到这个错误,因为我使用的语法似乎是正确的,而且它甚至可以正常运行.

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?

更新:

我在 vue 页面中使用手表的位置.

Location where i have used the watch in vue page.

推荐答案

你的组件定义中有类似 methods: { watch: {} } 的东西.这就是 vue 抱怨的原因.也可以通过 mixin 添加.

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.

这篇关于VueJS |方法“观看"具有类型“对象"在组件定义中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆