在Vuex插件中公开功能

时间:2018-02-11 04:39:57

标签: javascript plugins vue.js vuex

我正在尝试在Vuex插件中公开undo函数,以便在我的组件中用于点击事件。

// plugin.js
  const timeTravel = store => {
  // .. other things
  function undo () {
    store.commit('commit_something', payload)
  }
}

如何向组件公开undo功能以便我可以使用它?

1 个答案:

答案 0 :(得分:0)

Vuex插件不会在其上下文之外暴露任何内容。它们在接收商店对象时被挂钩到突变中。您的undo函数更适合作为商店/模块中的操作。

如果您有多个模块需要使用undo,请查看Module Reuse部分。

相关问题