vuex的結構是這樣的export default new Vuex.Store({
state:{
projects:[],
},
getters:{
getAllProjs(state){
return state.projects;
},
getProjectNamesById(state){
return state.projects.map( proj => proj.name )
}
},
mutations:{
pushProjectsToStore(state,data){
state.projects = data;
},
},
actions:{
pushProjectsToStore(){
}
}
})父組件創建時beforeCreate(){
this.$queryProject().then( res => this.$store.commit('pushProjectsToStore',res.data) )
},子組件實例化時mounted () { // 獲取項目信息
this.projects = this.$store.getters.getAllProjs;
this.projectNamesById = this.$store.getters.getProjectNamesById;
},然后現在有個問題,getAllProjs執行時機是在pushProjectsToStore之前,所以拿不到數據,請問如何解決
一個vuex state中的數據存取問題
拉風的咖菲貓
2018-07-15 18:26:52