zoukankan      html  css  js  c++  java
  • axios添加响应拦截器

    import $ajax from 'axios'
    $ajax.defaults.withCredentials = true;
    
    $ajax.interceptors.response.use( (response)=> {
      // 对响应数据做点什么
      // 显示
      console.log("添加响应拦截器", response)
      if (response.data.resultCode == 1999){
        // localStorage.setItem("userIsLogin", "true")
    
        window.location.reload();
    
      } else if (response.data.resultCode == 2000 && localStorage.getItem("resultCode") == "true"){
        localStorage.removeItem("resultCode")
        location.href = window.location.origin + "/weixin/dist/index.html#/"
      }
    
    
    
    
      if (response.data.data == null){
    
        Vue.$vux.toast.text(response.data.errorMessage, 'bottom')
    
      } else if (response.data.data.errorCode && response.data.data.errorCode != 0){
    
        Vue.$vux.toast.text(response.data.errorMessage, 'bottom')
    
    
    
        // response.config.url
    
      }
    
      return response.data.data;
    }, function (error) {
      // 对响应错误做点什么
      Vue.$vux.toast.text("服务器异常!", 'bottom')
    
    
      return Promise.reject(error);
    });
  • 相关阅读:
    Android开发环境
    安卓学习
    Shuffle'm Up POJ
    Duizi and Shunzi HDU
    Find a path HDU
    Cyclic Nacklace HDU
    Keywords Search HDU
    HDU 1495 非常可乐
    J
    Fire Game FZU
  • 原文地址:https://www.cnblogs.com/jongsuk0214/p/9364840.html
Copyright © 2011-2022 走看看