vuex中显示子模块中的state要怎么写,通过...mapState的方式?

selectModule子模块(module)有一个state值是keyword,可以通过this.$store.state.selectModule.keyword找到;
现在我想通过下面...mapState的扩展方法来写,要怎么写呢?keyword":"selectModule.keyword"这样写不行,见下面代码注释;
select.vue
store/index.js
importVuefrom"vue"
importVuexfrom"vuex"
import$from"jquery"
Vue.use(Vuex);
varselectModule={
state:{
keyword:60
},
getters:{
lists:function(){
varurl="https://easy-mock.com/mock/5a61abf341d8910ea886ec50/searchLists";
//return$.get(url,{},function(result){
//returnresult.lists;
//})
varresult={
lists:[
{
title:"数据一"
},
{
title:"数据二"
},
{
title:"数据三"
}
]
}
returnresult.lists;
}
},
mutations:{
changeKeyword:function(state,n){
state.keyword=n;
}
},
actions:{
changeAction:function(context,n){
context.commit("changeKeyword",n);
}
}
}
varstore=newVuex.Store({//注意这里的Store是大写
state:{
count:100,
count2:100
},
mutations:{
addIncrement:function(state,n){
setTimeout(function(){
state.count+=n;
},600)
},
reduce:function(state,n){
setTimeout(function(){
state.count-=n;
},600)
},
addIncrement2:function(state,n){
state.count2+=n;
},
reduce2:function(state,n){
state.count2-=n;
}
},
actions:{
addAction:function(context,n){
setTimeout(function(){
context.commit("addIncrement2",n);
},600)
},
reduceAction:function(context,n){
setTimeout(function(){
context.commit("reduce2",n);
},600)
}
},
getters:{
limitNum:function(state){
vara=state.count>120?120:state.count;
returna;
},
limitNum2:function(state){
vara=state.count2>120?120:state.count2;
returna;
}
},
modules:{
selectModule
}
})
exportdefaultstore
饮歌长啸
浏览 3606回答 3
3回答

小0白

标记。

qq_花开花谢_0

...mapState({//"keyword":"count"//count可以显示"keyword":state=>state.selectModule.keyword})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript