码迷,mamicode.com
首页 > 移动开发 > 详细

iview-admin里面的 axios 给包装了一层数据 libs/axios.js 数据做了一层拦截

时间:2019-09-25 15:52:39      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:state   nsf   eject   pass   ken   err   mock   添加   orm   

 

interceptors (instance, url) {
    // 请求拦截
    instance.interceptors.request.use(config => {
      // 添加全局的loading...
      if (!Object.keys(this.queue).length) {
        // Spin.show() // 不建议开启,因为界面不友好
      }
      this.queue[url] = true
      return config
    }, error => {
      return Promise.reject(error)
    })
    // 响应拦截
    instance.interceptors.response.use(res => {
      this.destroy(url)
      const { data, status } = res
      return { data, status }
    }, error => {
      this.destroy(url)
      let errorInfo = error.response
      if (!errorInfo) {
        const { request: { statusText, status }, config } = JSON.parse(JSON.stringify(error))
        errorInfo = {
          statusText,
          status,
          request: { responseURL: config.url }
        }
      }
      addErrorLog(errorInfo)
      return Promise.reject(error)
    })
  }

 

 

config: {transformRequest: {…}, transformResponse: {…}, timeout: 0, xsrfCookieName: "XSRF-TOKEN", adapter: ƒ, …}
data: {id: "1", username: "2", userpass: "3"}
headers: {content-type: "application/json; charset=utf-8", content-length: "40"}
request: MockXMLHttpRequest {custom: {…}, readyState: 4, responseURL: "http://127.0.0.1:8081/api/select.php", status: 200, statusText: "OK", …}
status: 200
statusText: "OK"
__proto__: Object

 

iview-admin里面的 axios 给包装了一层数据 libs/axios.js 数据做了一层拦截

标签:state   nsf   eject   pass   ken   err   mock   添加   orm   

原文地址:https://www.cnblogs.com/pengchenggang/p/11584612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!