zoukankan      html  css  js  c++  java
  • iview-admin里面的 axios 给包装了一层数据 libs/axios.js 数据做了一层拦截

    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
  • 相关阅读:
    SCCM2012 R2实战系列之七:软件分发(exe)
    man 手册--nc
    挂载虚拟机磁盘文件
    bond模式详解
    Windows下计算md5值
    man手册--iostat
    mount---挂载文件系统
    Linux-swap分区
    sync---强制将被改变的内容立刻写入磁盘
    vmstat---有关进程、虚存、页面交换空间及 CPU信息
  • 原文地址:https://www.cnblogs.com/pengchenggang/p/11584612.html
Copyright © 2011-2022 走看看