亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

一個vuex state中的數據存取問題

一個vuex state中的數據存取問題

qq_笑_17 2018-08-29 14:43:24
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之前,所以拿不到數據,請問如何解決
查看完整描述

2 回答

?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

computed: {

...mapGetters(["getAllProjs","getProjectNamesById"])

},
watch:{

getAllProjs(newVal,oldVal){
    console.log('vuex 中上一次的值',oldVal);
    console.log('vuex 中更新后的值',newVal);
},
getProjectNamesById(newVal,oldVal){

}

}


查看完整回答
反對 回復 2018-09-09
  • 2 回答
  • 0 關注
  • 987 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號