【问题标题】:Vue Typeerror Method is not a funcion?Vue Typeerror 方法不是函数?
【发布时间】:2020-06-07 09:53:18
【问题描述】:
    Uncaught TypeError: Object(...) is not a function
        at eval (Auth.vue?7df1:27)

这是我的错误。

linter 没有给出任何错误,我看不到任何错误。 Devtools 说方法是对象类型,因此不能作为函数调用。

真的不知道这里发生了什么。

      methods: {
        submitForm: () => {
          this.login(this.userData)
            .then((response) => {
              // eslint-disable-next-line
              console.log(response);
              this.$router.push('/');
            })
            .catch((error) => {
              // eslint-disable-next-line
              console.log(error);
            });
        },
        ...mapActions(['login']),

【问题讨论】:

  • 我怀疑 this 是否可以使用箭头函数,您可能需要使用通常的 function 声明它
  • 所以我将错误缩小到...mapActions 后面的the method 块内。

标签: javascript vue.js axios frontend


【解决方案1】:

它是一个对象submitForm:,它包含一个匿名函数() => {...},但它仍然是一个对象。

使用submitForm() { ... } 作为简写。这扩展为submitForm: function () {},而您所拥有的仍然是对象内部的匿名函数,从而给您错误。

【讨论】:

  • 刚刚更改了它,但它抛出了同样的错误。这就是我最初拥有代码的方式,它给出了这个错误,这让我很惊讶,因为我确信这是正确的。
猜你喜欢
  • 2019-02-15
  • 2020-02-20
  • 2020-06-05
  • 2023-03-12
  • 1970-01-01
  • 2021-06-28
  • 1970-01-01
  • 2017-06-20
  • 2021-12-13
相关资源
最近更新 更多