我正在嘗試在我的其他計算屬性中使用 mapGetters 值。它顯示 null 因為首選項方法未執行完成。我想等到商店設定getter和setter。我試過異步/等待,但它不作業
mounted() {
this.preferences();
this.selectedColumnsHeader;
},
methods: {
async preferences() {
await this.$store.dispatch('fetchPreferences');
}
}
店鋪
fetchPreferences({ commit }) {
return http
.get('/help_ticket_preferences.json')
.then((res) => {
commit('setPreferences', res.data.preference);
})
.catch((error) => {
commit('setErrorMessage', `Sorry, there was an error fetching help ticket preferences ${error.message}.`);
});
},
uj5u.com熱心網友回復:
首先,你需要等待this.preferences()inmounted
async mounted() {
await this.preferences();
this.selectedColumnsHeader;
},
其次,您需要在fetchPreferences
fetchPreferences({ commit }) {
return http
.get('/help_ticket_preferences.json')
..... etc
有幫助的鋤頭
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/465372.html
標籤:javascript Vue.js 异步等待
