【问题标题】:Action is not defined as a method in the component vue.js动作在组件 vue.js 中没有定义为方法
【发布时间】:2020-07-30 11:58:38
【问题描述】:

我正在尝试将操作作为组件中的方法访问,但出现错误

this.delete_notifaction 不是函数

notifaction.js

export const actions = {
  add_notifaction({ commit }, notifaction) {
   commit("ADD_NOTIFACTION", notifaction);
  },
  delete_notifaction({ commit }, notificationToRemove) {
   commit('DELETE_NOTIFACTION', notificationToRemove)
  }
};

store/index.js

modules : {
  notifaction
},

Component.vue

methods: mapActions('notifaction',["delete_notifaction"]),
mounted() {
   this.delete_notifaction(this.notification);
}

有什么帮助吗?

【问题讨论】:

  • 您能否检查一下您的组件定义中是否只有一个methods 部分?

标签: vue.js


【解决方案1】:

试试这个

methods: {
   ...mapActions(['delete_notifaction']),
}

请参阅此处了解展开语法 https://stackoverflow.com/a/48137766/10118668

【讨论】:

    猜你喜欢
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 2019-06-13
    相关资源
    最近更新 更多