From 7df9b513447d8deab2fd8e86fa23c807adb6d440 Mon Sep 17 00:00:00 2001 From: love-life <75002215+ljw-codeking@users.noreply.github.com> Date: Thu, 9 Sep 2021 09:41:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9axios=20=E4=B8=AD=20ur?= =?UTF-8?q?lPrefix=20=E5=AD=97=E6=AE=B5=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#1170)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(样式污染): 会污染其他带有srcollbar的组件样式 * fix(axios): urlPrefix 字段传递不生问题效 --- src/utils/http/axios/axiosTransform.ts | 1 - src/utils/http/axios/index.ts | 8 +++++--- types/axios.d.ts | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/http/axios/axiosTransform.ts b/src/utils/http/axios/axiosTransform.ts index 1581b963..f6cbc80a 100644 --- a/src/utils/http/axios/axiosTransform.ts +++ b/src/utils/http/axios/axiosTransform.ts @@ -6,7 +6,6 @@ import type { RequestOptions, Result } from '/#/axios'; export interface CreateAxiosOptions extends AxiosRequestConfig { authenticationScheme?: string; - urlPrefix?: string; transform?: AxiosTransform; requestOptions?: RequestOptions; } diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index 4affadad..c5c3fa46 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -81,7 +81,7 @@ const transform: AxiosTransform = { // 请求之前处理config beforeRequestHook: (config, options) => { - const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options; + const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true,urlPrefix } = options; if (joinPrefix) { config.url = `${urlPrefix}${config.url}`; @@ -199,8 +199,7 @@ function createAxios(opt?: Partial) { timeout: 10 * 1000, // 基础接口地址 // baseURL: globSetting.apiUrl, - // 接口可能会有通用的地址部分,可以统一抽取出来 - urlPrefix: urlPrefix, + headers: { 'Content-Type': ContentTypeEnum.JSON }, // 如果是form-data格式 // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED }, @@ -222,6 +221,8 @@ function createAxios(opt?: Partial) { errorMessageMode: 'message', // 接口地址 apiUrl: globSetting.apiUrl, + // 接口拼接地址 + urlPrefix: urlPrefix, // 是否加入时间戳 joinTime: true, // 忽略重复请求 @@ -240,5 +241,6 @@ export const defHttp = createAxios(); // export const otherHttp = createAxios({ // requestOptions: { // apiUrl: 'xxx', +// urlPrefix: 'xxx', // }, // }); diff --git a/types/axios.d.ts b/types/axios.d.ts index e325b65b..e60187f9 100644 --- a/types/axios.d.ts +++ b/types/axios.d.ts @@ -14,6 +14,8 @@ export interface RequestOptions { joinPrefix?: boolean; // Interface address, use the default apiUrl if you leave it blank apiUrl?: string; + // 请求拼接路径 + urlPrefix?: string; // Error message prompt type errorMessageMode?: ErrorMessageMode; // Whether to add a timestamp