争渡,争渡,惊起一滩鸥鹭

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

import Axios from 'axios'
import { Loading, Message } from 'element-ui'

// 超时时间
Axios.defaults.timeout = 5000
// http请求拦截器
let loadinginstace
Axios.interceptors.request.use(config => {
   // element ui Loading方法
   loadinginstace = Loading.service({ fullscreen: true })

   return config
}, error => {
   loadinginstace.close();

  return Promise.reject(error)
})

// http响应拦截器
Axios.interceptors.response.use(data => {
   // 响应成功关闭loading
   loadinginstace.close();
  const code = data.data.code;
  if(code == 501) { //未登录
  }
  
return data }, error => { loadinginstace.close();   const code = error.data.code;   // 此处判断拦截需要处理的错误状态码并处理   if(code == 502) {      }
  
return Promise.reject(error) })

 

参考文档:https://www.cnblogs.com/duanzhenzhen/p/10663496.html

posted on 2020-02-04 19:33  争渡~  阅读(9349)  评论(0)    收藏  举报