Answer the question
In order to leave comments, you need to log in
Why does the store.getters in the Router get beforeEnter before the axios in the Vuex actions has completed?
In actions there is an axios request
But in the router in beforeEnter store.getters receives old data and does not have time to receive new ones
. What is the reason?
path: '/test',
name: 'test',
component: test,
beforeEnter: (to, from, next) => {
if (!store.getters.get_test_id) {
next({ name: 'error' });
} else {
next();
}
},
state: {
test_id: null
},
mutations: {
set_test_id(state, n) {
state.test_id = n;
},
},
getters: {
get_test_id: state => state.test_id,
},
actions: {
regID({ commit }) {
axios.post('/site/')
.then((response) => {
commit('set_test_id', response.data); // response.data = 555
});
},
},
const app = new Vue({
router,
render: h => h(App),
store,
created() {
store.dispatch('regID');
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question