电子的Vuex动作调度问题

Dai*_*mos 2 javascript vue.js electron vuex vuex-modules

我有Vuex的电子应用程序。使用模块(我的测试模块Browser.js)为整个应用配置了商店:

export default {
  namespaced: true,
  state: {
    currentPath: 'notSet'
  },
  mutations: {
    setPath (state) {
      state.currentPath = 'xxxx'
    }
  },
  actions: {
    updateCurrentPath ({ commit }) {
      console.log('COMMIT')
      commit('setPath')
    }
  },
  getters: {
    getCurrentPath (state) {
      return state.currentPath
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

现在,在组件Im中尝试分发更新操作失败。吸气剂工作正常:

mounted () {
  console.log('mounted')
  console.log('# GET FROM STORE:', this.$store.getters['Browser/getCurrentPath'])
  console.log('# DISPATCH:', this.$store.dispatch('Browser/updateCurrentPath'))
  console.log('# GET FROM STORE 2:', this.$store.getters['Browser/getCurrentPath'])
},
Run Code Online (Sandbox Code Playgroud)

安慰:

mounted
Browser.vue?31a5:62 # GET FROM STORE: notSet
Browser.vue?31a5:63 # DISPATCH: undefined
Browser.vue?31a5:64 # GET FROM STORE 2: notSet
Run Code Online (Sandbox Code Playgroud)

动作存在,当我记录this。$ store变量时,我可以看到:

Store {_committing: false, _actions: {…}, _actionSubscribers: Array(0), _mutations: {…}, _wrappedGetters: {…}, …}
_actions:
Browser/updateCurrentPath
Run Code Online (Sandbox Code Playgroud)

那么我应该如何调度行动?

Dai*_*mos 9

问题出在电子插件上。我使用的是来自github的electronic-vue仓库,并且使用了一个插件:

export default new Vuex.Store({
  modules,
  plugins: [
    createPersistedState(),
    createSharedMutations()
  ],
  strict: process.env.NODE_ENV !== 'production'
})
Run Code Online (Sandbox Code Playgroud)

createSharedMutations插件是问题所在。注释掉之后,一切正常:

export default new Vuex.Store({
  modules,
  plugins: [
    createPersistedState()
  ],
  strict: process.env.NODE_ENV !== 'production'
})
Run Code Online (Sandbox Code Playgroud)