学vuex关于modules的时候有点乱,
`
new Vuex.Store({
state: {conut:0},//$store.state.count
moudules: {
account:{
state:{count:1},//$store.state.account.count
moudules:{
myPage:{
state:{count:2}//?
}
}
}
}
})//如何获得各个state里的count?`
new Vuex.Store({
state: {conut:0},//$store.state.count
moudules: {
account:{
namespaced: true,
state:{count:1},
moudules:{
myPage:{
state:{count:2}
},
myPage2:{
namespaced: true,
state:{count:1}
}
}
}
}
})//如何获得各个state里的count?
const store = new Vuex.Store({
modules: {
account: {
namespaced: true,
getters: {
isAdmin () { ... } // -> getters['account/isAdmin']
},//【请看这里】如果把上面的isAdmin改为profile
//不是也变成了getters['account/profile']和未加命名空间的嵌套module一样吗
actions: {
login () { ... } // -> dispatch('account/login')
},
mutations: {
login () { ... } // -> commit('account/login')
},
// 嵌套模块
modules: {
// 继承父模块的命名空间
myPage: {
state: { ... },
getters: {
profile () { ... } // -> getters['account/profile']
}
},
// 进一步嵌套命名空间
posts: {
namespaced: true,
state: { ... },
getters: {
popular () { ... } // -> getters['account/posts/popular']
}
}
}
}
}
})
...
computed: {
...mapState({
a: state => state.some.nested.module.a,//【请看这里】some.nested.module
//nested指的是普通嵌套模块的state,还是带有命名空间的嵌套模块的state,
//如果是后者那普通嵌套模块的state和模块的state如何区别?
})
}
希望能有熟悉vuex的大神帮我解决困惑,大恩不言谢!