- 调用某接口,发现token需要更新,response.config记录着我们上一次请求的结果
http.interceptors.response.use(async response => {
localStorage.setItem('token', response.data.refreshToken)
let refreshRequest = () => {
return new Promise((resolve, reject) => {
http(response.config).then(data => {
resolve(data)
}).catch((e) => {
reject(e)
})
})
}
let res = await refreshRequest()
return Promise.resolve(res)
})