serii81
@serii81
Я люблю phр...

Почему не работает axios в nuxtServerInit?

Сайт nuxt + strapi

Через postman запрос работает.
F2edjta.png

.env
API_URL=http://localhost:1337/api

nuxt.config.js
axios: {
    // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
    baseURL: process.env.API_URL,
  },


store/index.js
export const state = () => ({
  option: null,
});

export const mutations = {
  setOption(state, payload) {
    state.option = payload;
  },
};

export const actions = {
  async nuxtServerInit({ dispatch }) {
    await dispatch("storeDispatchFunc");
  },
  async storeDispatchFunc({ commit }) {
    this.$axios
      .get("/option")
      .then((res) => {
        console.log(res, "res");
        commit("setOption", res);
      })
      .catch((error) => {
        console.log(error, "error");
      });
  },
};


pV0XZw0.png

Почему в браузере option null?

stWkePz.png
  • Вопрос задан
  • 120 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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