From f48a086c6c5b1eaadba61a2ed7a7fe0850e6aefe Mon Sep 17 00:00:00 2001 From: duanxiaohai <1812246227@qq.com> Date: Fri, 24 May 2024 15:49:50 +0800 Subject: [PATCH] gx --- src/utils/request.js | 56 ++++++++++++++++++++++---------------------- vite.config.js | 4 ++-- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index e141e71..7ce055b 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -21,34 +21,34 @@ axios.interceptors.request.use( ); // HTTP response 拦截器 -// axios.interceptors.response.use( -// (response) => { -// return response; -// }, -// (error) => { -// if (error.response) { -// if (error.response.status == 401) { -// ElMessage.error("请重新登录!"); -// // window.location.href = '/#/login?returnURL=' + window.location.href -// window.location.href = -// 'http://220.191.238.50:996/api/login?returnURL=' + -// window.location.href -// } else if (error.response.status == 404) { -// ElMessage.error("Status:404,正在请求不存在的服务器记录!"); -// } else if (error.response.status == 500) { -// ElMessage.error({ -// title: '请求错误', -// message: "Status:500,服务器发生错误!" -// }); -// } else { -// ElMessage.error(`Status:${error.response.status},未知错误!`); -// } -// } else { -// ElMessage.error("请求服务器无响应!"); -// } -// return Promise.reject(error.response); -// } -// ); +axios.interceptors.response.use( + (response) => { + return response; + }, + (error) => { + if (error.response) { + if (error.response.status == 401) { + ElMessage.error("请重新登录!"); + // window.location.href = '/#/login?returnURL=' + window.location.href + window.location.href = + 'http://220.191.238.50:996/api/login?returnURL=' + + window.location.href + } else if (error.response.status == 404) { + ElMessage.error("Status:404,正在请求不存在的服务器记录!"); + } else if (error.response.status == 500) { + ElMessage.error({ + title: '请求错误', + message: "Status:500,服务器发生错误!" + }); + } else { + ElMessage.error(`Status:${error.response.status},未知错误!`); + } + } else { + ElMessage.error("请求服务器无响应!"); + } + return Promise.reject(error.response); + } +); var http = { diff --git a/vite.config.js b/vite.config.js index e43c9bf..aeacc20 100644 --- a/vite.config.js +++ b/vite.config.js @@ -15,8 +15,8 @@ export default defineConfig({ // 第一个代理 "/api": { // 匹配到啥来进行方向代理 - target: "http://192.168.1.2:8095/", //本地 - // target: "http://220.191.238.50:996/", //线上 + // target: "http://192.168.1.2:8095/", //本地 + target: "http://220.191.238.50:996/", //线上 changeOrigin: true, //是否支持跨域 //rewrite: (path) => path.replace(/^\/api/, '') // 如果不需要api 直接把路径上的api 替换成空,这个 },