interceptors (instance, URL) { // request interceptor instance.interceptors.request.use (config => { // add global ... loading IF (! Object.keys ( the this .queue) .length) { // Spin the .Show () // not recommended to open, because the interface unfriendly } the this .queue [URL] = to true return config }, error => { return Promise.reject (error) }) // response intercept instance.interceptors.response. use (RES => { the 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