From b9266bfc4fbc3ed2d0811a037cc1481eaeb5c6ad Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Thu, 29 Aug 2024 22:02:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drequest=E5=B0=81=E8=A3=85?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tonecn/src/lib/request.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/tonecn/src/lib/request.ts b/tonecn/src/lib/request.ts index 28fcc82..33c2aec 100644 --- a/tonecn/src/lib/request.ts +++ b/tonecn/src/lib/request.ts @@ -1,23 +1,10 @@ import axios from "axios"; -axios.defaults.baseURL = "http://localhost:8080"; - -interface ResponseData { - code: number; - msg: string; - data: T; -} +axios.defaults.baseURL = "http://localhost:23500"; axios.interceptors.response.use((response) => { - // 确保响应数据符合ResponseData接口的结构 - const responseData: ResponseData = response.data; - // 根据code值做不同的处理 - if (responseData.code === 200) { // 假设200为成功的code - return responseData.data; // 当成功时,只返回data字段 - } else { - // 当不成功时,抛出整个responseData或创建一个Error对象 - throw new Error(`请求错误: ${responseData.msg}`); - } + // 确保响应数据符合ResponseData接口的结构 + return response.data; }); export { axios as request }; \ No newline at end of file