here is the code that I use vuex.
I search this error on google ,and some answer said this is because of the "namespaced:true",so I comment this line ,but the error still exist.
Also,If I directly use the test ,every thing is just fine.But when I put it in modules,It doesn't work.
//src/store/index.js
import { createStore } from 'vuex'
import test from './modules/test'
export default createStore({
modules: {
test
}
})
//src/store/modules/test.js
import { createStore } from 'vuex'
export default createStore({
namespaced: true,
state () {
return {
count: 0
}
},
mutations: {
increment (state) {
state.count
}
},
actions: {
action_increment ({ commit }) {
commit('increment')
}
}
})
the way I use it
methods: {
test () {
this.$store.dispatch('test/action_increment')
}
}
CodePudding user response:
You shouldn't create a new store for your module. Look here https://vuex.vuejs.org/guide/modules.html