Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store state not update by using store code splitting #284

Open
cyany opened this issue May 21, 2020 · 0 comments
Open

store state not update by using store code splitting #284

cyany opened this issue May 21, 2020 · 0 comments

Comments

@cyany
Copy link

cyany commented May 21, 2020

here is my code:
`
home.vue
async asyncData({ store, route }) {
store.registerModule('homepc', homepcStoreModule)
return store.dispatch("homepc/getHot");
},
mounted(){
this.$refs.changeHot2.addEventListener('click',function(){
_that.getHotLists();
})
}
methods:{
getHotLists(){
return this.$store.dispatch("a/getHot");
},
}

store/index.js
import Vue from "vue";
import Vuex from "vuex";
import moduleHomePc from "./homepc"

Vue.use(Vuex);

export function CreateStore() {
return new Vuex.Store({
modules:{
a:moduleHomePc
}
})
}

store/homepc.js
import Vue from "vue";
import homePc from "./../assets/js/homePc.js";
export default {
namespaced: true,
state: ()=>({
hotLists:[]
}),
mutations: {
getHotLists(state, payload) {
console.log(state,'hot')// !!!but state is empty object like {hotLists:[]}
Vue.set(state, 'hotLists', payload);
}
},
actions: {
getHot({ commit }) {
return homePc.getHotLists({}).then(res => {
if (res.data.code == '0') {
commit('getHotLists', res.data.list);
}
});
},
}
`

I debuged the code console.log(state),open the brower debug mode ,the state is not update.
anynone can give a tip ,thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant