Bootstrap

axios请求token失效用新token重新请求

token失效请求返回新token再次请求的情况

post (target, params = {}) {
      let suffix = Object.keys(params).map(name => {
        return `${name}=${params[name]}`
      }).join('&')
      let urls = suffix.length > 0 ? `${target}?${suffix}` : `${target}`
      return new Promise((resolve, reject) => {
        let urls1=urls//保存地址 
        axios.post(urls).then(res => {
          if(res.status==200){
            resolve(res.data)
                //验证是否含有token切不是登录接口
          }else if (res.data.hasOwnProperty('accessToken')&&urls1.indexOf('login')<0) {
                //再次请求
            axios.post(urls1).then(res => {
              resolve(res)
            }).catch((err) => {
              reject(err)
            })
          }else{
            resolve(res)
          }
        }).catch((err) => {
          reject(err)
        })
      })
    },

 

;