• 调用某接口,发现token需要更新,response.config记录着我们上一次请求的结果
      1. http.interceptors.response.use(async response => {
      2. localStorage.setItem('token', response.data.refreshToken)
      3. let refreshRequest = () => {
      4. return new Promise((resolve, reject) => {
      5. http(response.config).then(data => {
      6. resolve(data)
      7. }).catch((e) => {
      8. reject(e)
      9. })
      10. })
      11. }
      12. let res = await refreshRequest()
      13. return Promise.resolve(res)
      14. })