Global http response error handling in vue/axios with vuex

前端 未结 3 1365
难免孤独
难免孤独 2021-01-22 19:59

I\'m trying to fix a behavior in my VueJS SPA wherein a limbo state arises. The app doesn\'t know the JWT has already expired and therefore presents itself as if the user is sti

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 20:33

    Base on these thread I was able to manage a solution for my needs:

    main.js

    import api, {apiConfig} from 'Api/api'
    apiConfig({ store: $store });
    

    ApiClient.js

    let configs = {
      store: undefined,
    };
    const apiConfig = ({ store }) => {
      configs = { ...configs, store };
    };
    export default api;
    export { apiConfig };
    

    This way the api.js file will require a configuration that can later be expanded.

提交回复
热议问题