From b433c10b0b03805243f9d7b35a111c9475328d15 Mon Sep 17 00:00:00 2001 From: ovo Date: Sat, 7 Dec 2024 13:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index f985a02..9176ec1 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -34,8 +34,15 @@ service.interceptors.request.use( // 响应拦截器 service.interceptors.response.use( (response: AxiosResponse) => { - // 直接返回整个响应数据,而不是只返回 data - return response.data + const { code, message, data } = response.data + + // 根据后端约定的状态码处理 + if (code === 200) { + return data + } else { + ElMessage.error(message || '请求失败') + return Promise.reject(new Error(message || '请求失败')) + } }, (error) => { const { status } = error.response || {}