From 3b5293a5edb03e3067a26952b6e99b226bdc9822 Mon Sep 17 00:00:00 2001 From: 86183 <747682928@qq.com> Date: Thu, 9 Nov 2023 21:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86Axios=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=AE=9E=E4=BE=8B=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index adaae74..d4bce55 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -16,8 +16,9 @@ let apiBaseUrl = window._CONFIG['domianURL'] || "/jeecg-boot"; // 创建 axios 实例 const service = axios.create({ //baseURL: '/jeecg-boot', - baseURL: apiBaseUrl, // api base_url - timeout: 9000 // 请求超时时间 + // baseURL: apiBaseUrl, // api base_url + baseURL: 'http://localhost:8080/jeecg-boot', + timeout: 15000 // 请求超时时间 }) const err = (error) => { @@ -69,7 +70,7 @@ const err = (error) => { } break case 404: - Vue.prototype.$Jnotification.error({ message: '系统提示', description:'很抱歉,资源未找到!',duration: 4}) + Vue.prototype.$Jnotification.error({ message: '系统提示', description:'很抱歉,资源未找到!',duration: 4}) break case 504: Vue.prototype.$Jnotification.error({ message: '系统提示', description: '网络超时'}) @@ -144,7 +145,16 @@ service.interceptors.request.use(config => { // response interceptor service.interceptors.response.use((response) => { return response.data - }, err) + }, error=> { + if(error.code==='ECONNABORTED' && error.message.indexOf('timeout')!==-1){ + Vue.prototype.$Jnotification.error({message: '系统提示', description: '网络超时'}) + } + else{ + Vue.prototype.$Jnotification.error({message: '系统提示', description: '未知错误'}) + } + return Promise.reject(error) + } +) const installer = { vm: {},