selectModule子模块(module)有一个state值是keyword,可以通过this.$store.state.selectModule.keyword找到;现在我想通过下面...mapState的扩展方法来写,要怎么写呢?keyword":"selectModule.keyword"这样写不行,见下面代码注释;select.vueimport{mapState,mapMutations,mapActions,mapGetters}from"vuex"exportdefault{name:'app',data(){return{}},computed:{...mapState({//"keyword":"count"//count可以显示"keyword":"selectModule.keyword"//selectModule.keyword显示不出来???})},methods:{isShowFun:function(){this.$emit("isShowFun2");}},created:function(){}}store/index.jsimportVuefrom"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
添加回答
举报
0/150
提交
取消