我有带有 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
}
}
}
现在在组件内部我试图发送更新操作但没有成功。吸气剂工作正常:
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'])
},
安慰:
mounted
Browser.vue?31a5:62 # GET FROM STORE: notSet
Browser.vue?31a5:63 # DISPATCH: undefined
Browser.vue?31a5:64 # GET FROM STORE 2: notSet
动作存在,当我记录 this.$store 变量时,我可以看到:
Store {_committing: false, _actions: {…}, _actionSubscribers: Array(0), _mutations: {…}, _wrappedGetters: {…}, …}
_actions:
Browser/updateCurrentPath
那么我应该如何调度动作呢?