我有这个Vuex模块:
//modules/things.js
const state = {
firstThing: 'abc',
secondThing: 'def',
};
const getters = {
getFirstThing: state => state.firstThing,
getSecondThing: state => state.secondThing,
};
const mutations = {
setFirstThing: (state, payload) => state.firstThing = payload,
setSecondThing: (state, payload) => state.secondThing = payload
};
const actions = {};
export default {
namespaced: true, // <------
state,
mutations,
actions,
getters
};
Run Code Online (Sandbox Code Playgroud)
我使用namespaced: true flag,可以像这样使用这个模块:
this.$store.state.things.firstThing // <-- return abc here
this.$store.commit('things/setFirstThing', 10)
this.$store.getters['things/getFirstThing'] // <-- return abc here
Run Code Online (Sandbox Code Playgroud)
如果我将使用像Vuex 官方示例中的 …