【问题标题】:VueJS | Method "watch" has type "object" in the component definitionVueJS |方法“watch”在组件定义中有类型“object”
【发布时间】:2020-12-15 07:48:12
【问题描述】:

目前我在Product.vue 文件中有关注手表

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 警告)

[Vue 警告]:方法“watch”在组件定义中具有类型“object”。您是否正确引用了该函数?

我不确定为什么会收到此错误,因为我使用的语法似乎是正确的,甚至可以正常运行。

有什么建议为什么它在错误控制台中给出这个警告?


更新:

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

【问题讨论】:

  • methods 对象中是否有名为 watch 的方法?
  • @OrkhanAlikhanov,在方法结束大括号之后没有。我已经添加了我使用它的屏幕截图。
  • 如果你删除async/await?
  • 你能显示你的对象的完整定义并删除了方法体吗?
  • 您在组件定义中有类似methods: { watch: {} } 的内容。这就是错误。 methods 应该只包含方法,而不是对象

标签: vue.js vuejs2 vue-storefront


【解决方案1】:

您的组件定义中有类似methods: { watch: {} } 的内容。这就是vue抱怨的原因。 mixin 也可以添加它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-21
    • 1970-01-01
    • 2021-07-16
    • 2020-02-03
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    • 2019-07-13
    相关资源
    最近更新 更多