@Vitalionus

Почему store.getters в Роутере beforeEnter получает до того как в Vuex actions отработает axios?

В actions идет запрос axios
Но в роутере в beforeEnter store.getters получает старые данные и не успевает получить новые
В чем причина?
path: '/test',
    name: 'test',
    component: test,
    beforeEnter: (to, from, next) => {
      if (!store.getters.get_test_id) {
        next({ name: 'error' });
      } else {
        next();
      }
    },


Это в store
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
        });
    },
  },

Как сделать что бы в роутер успевал получить test_id измененную?

В main.js
const app = new Vue({
  router,
  render: h => h(App),
  store,
  created() {
    store.dispatch('regID');
  },
  • Вопрос задан
  • 229 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы