Vuex 模組化與專案例項 (2.0)
阿新 • • 發佈:2019-01-25
const moduleA = { state: { count: 1 }, mutations: { sayCountA(state) { console.log('Module A count: ', state.count); } }, actions: { maAction(context) { context.dispatch('mbAction'); } } }; const moduleB = { state: { count:2 }, mutations: { sayCountB(state, num) { console.log('Module B count: ', state.count+num); } }, action: { mbAction({ commit, rootState }) { commit('sayCountA'); commit('sayCountB', rootState.a.count); } } }; const store= { modules: { a: moduleA, b: moduleB } }; store.dispatch('maAction'); // Module A count: 1、Module B count: 3