fix: 修改axios 中 urlPrefix 字段不生效问题 (#1170)

* fix(样式污染): 会污染其他带有srcollbar的组件样式

* fix(axios): urlPrefix 字段传递不生问题效
This commit is contained in:
love-life 2021-09-09 09:41:34 +08:00 committed by GitHub
parent c753d945e0
commit 7df9b51344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -6,7 +6,6 @@ import type { RequestOptions, Result } from '/#/axios';
export interface CreateAxiosOptions extends AxiosRequestConfig {
authenticationScheme?: string;
urlPrefix?: string;
transform?: AxiosTransform;
requestOptions?: RequestOptions;
}

View File

@ -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<CreateAxiosOptions>) {
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<CreateAxiosOptions>) {
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',
// },
// });

2
types/axios.d.ts vendored
View File

@ -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