动作未在组件vue.js中定义为方法

时间:2020-04-17 03:56:38

标签: vue.js

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

错误

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

有帮助吗?

1 个答案:

答案 0 :(得分:0)

尝试一下

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

请参阅此处以了解传播语法 https://stackoverflow.com/a/48137766/10118668