账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    如何在axios二次封装文件中访问到vue新的实例,为什么为访问到的vuex的实例是undefined
    29
    0

    vuex:

    const store = new Vuex.Store({
      state,
      getters,
      actions,
      mutations,
      plugins: [createLogger()]
    });
    
    export default store;

    axios:二次封装

    import axios from 'axios';
    import ip, {token} from './ip';
    import store from '@/store';
    console.log(store); // 访问到的store是undefined
    
    import Store from '@/utils/store';
    
    
    // 禁止带cookie请求
    axios.defaults.withCredentials = false;
    // 添加请求拦截器
    axios
      .interceptors
      .request
      .use(config => {
        config.headers.common['Authorization'] = Store.get('token');
        return config;
      }, error => {
        return Promise.reject(error);
      });
    
    export default axios;
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部