41 lines
592 B
JavaScript
41 lines
592 B
JavaScript
|
// 商品相关
|
||
|
const moduleA = {
|
||
|
state: () => ({
|
||
|
count: 0
|
||
|
}),
|
||
|
mutations: {
|
||
|
increment (state) {
|
||
|
// 这里的 `state` 对象是模块的局部状态
|
||
|
state.count++
|
||
|
}
|
||
|
},
|
||
|
getters: {
|
||
|
doubleCount (state) {
|
||
|
return state.count * 2
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// 用户相关
|
||
|
const moduleB = {
|
||
|
state: () => ({
|
||
|
count: 0
|
||
|
}),
|
||
|
mutations: {
|
||
|
increment (state) {
|
||
|
// 这里的 `state` 对象是模块的局部状态
|
||
|
state.count++
|
||
|
}
|
||
|
},
|
||
|
getters: {
|
||
|
doubleCount (state) {
|
||
|
return state.count * 2
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const store = new Vuex.Store({
|
||
|
modules: {
|
||
|
shop: moduleA,
|
||
|
user: moduleB
|
||
|
}
|
||
|
})
|