import axios from "axios";import { Message } from "element-ui";// Add a response interceptoraxios.interceptors.response.use(function (response) { // Any status code that lie within the range of 2xx cause this function to trigger // Do something with response data return response; }, function (error) { // Any status codes that falls outside the range of 2xx cause this function to trigger // Do something with response error // 如果错误信息里包括 timeout 字符串,就表示请求超时,给出提示 if (error.message.includes('timeout')) { Message.warning('Request timeout, please try again'); } return Promise.reject(error); });
如果各位大佬有更好的方案,请在下方留言,谢谢。