Use respone interceptor to solve the problem

    import axios from 'axios'// Create an instance of axios const service = axios.create({baseURL:""// There are some situations when you can call one address and another address timeout: 5000, // The time when you can call with the credentials:true, / / allowed cookies}) / / request processing service. The interceptors. Request. Use (config = > {/ / console log (config); // config.headers['X-Requested-With'] = 'XMLHttpRequest'
    // request.headers.set('token', token); Promise. Reject (error) // Do something before sending the requestreturnconfig }, error => { Promise.reject(error).catch() } ), / / respone interceptor service. Interceptors. Response. Use (response = > {/ / const hea = response. The headers. // const res = response.data; // const sta=response.StatusCode; // const url=response.request.responseURL; // The method that deletes a cookie with javascript, passing in the name of the cookie to deletefunction RemoveCookie(cookieName) {
        var cookies = document.cookie.split(";"); // Divide all cookie key-value pairs into arrays with semicolons // loop over all cookie key-value pairsfor(var i = 0; i < cookies.length; I++) {// some cookie key-value pairs will have a blank in front of them for no reasonif (cookies[i].indexOf("") == 0) { cookies[i] = cookies[i].substring(1); } // Compare the name of each cookie to find the cookie key-value pair to deleteif(cookies[i].indexOf(cookieName) == 0) { var exp = new Date(); Exp. SetTime (exp. GetTime () -60 * 1000); Exp = cookie [I] +; exp = cookie [I] +; exp = cookie [I] +"; expires="+ exp.toUTCString(); // Set the expiration time of the cookie to be deleted. That is, add an expires key value pair after the cookie and assign the above exp to expires. The browser will delete the cookie immediately. // Note that the document. Cookie is very clever. But retrieving the value of document.cookie returns information about all cookies console.log("Code clean completed")
                break; // The cookie to be deleted has already been deleted in the client, out of the loop}}}if(response.status=="200"){
      RemoveCookie("code")
        
    }
    /* console.log(response)
    if(sta=="200"){
          console.log(hea)
          window.location.href = hea['Location']}if(! Res.status) {// Titan framework before 1.8.6. The back-end session expiresif (sta =='302') {
        // console.log(1111)
         window.location.href = hea['Location'} // The front and rear ends are separated, Titan frame 1.8.6 and above. Replace 302 reload // var MSG = response.data.message // with this codeif (msg && msg.indexOf('oauth2/authorize') !== -1) {
      //   window.location.href = msg
      //   return/ / / /}return Promise.reject('error').catch()
      return response
    } else{// Request successful */returnResponse //}}, error => {// by default, everything except 2XX is in errorif (error.response) {
      if(error.response.status=="401") {let test = window.location.href;
        var code=' ' 
          if (test.indexOf("?")! Var STR = test.substr(1); var STR = test.substr(1); // Start with the first character because the 0th character is? Var STRS = str.split("="); Var len= STRS [1].split() var len= STRS [1].split()"&") code=len[0]; // popup the first argument (loop if there are multiple arguments)} document.cookie="code="+code+"";
        window.location.href = error.response.data.message
      }else if(error.response.status=="403") {let test = window.location.href;
        window.location.href =test+"403"
      }else if(error.response.status=="500") {let test = window.location.href;
        window.location.href =test+"500"}}return Promise.reject(error.response).catch()
  }
)

export default service

Copy the code