mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-02-03 02:54:40 +08:00
fix: 修改axios 中 urlPrefix 字段不生效问题 (#1170)
* fix(样式污染): 会污染其他带有srcollbar的组件样式 * fix(axios): urlPrefix 字段传递不生问题效
This commit is contained in:
parent
c753d945e0
commit
7df9b51344
@ -6,7 +6,6 @@ import type { RequestOptions, Result } from '/#/axios';
|
|||||||
|
|
||||||
export interface CreateAxiosOptions extends AxiosRequestConfig {
|
export interface CreateAxiosOptions extends AxiosRequestConfig {
|
||||||
authenticationScheme?: string;
|
authenticationScheme?: string;
|
||||||
urlPrefix?: string;
|
|
||||||
transform?: AxiosTransform;
|
transform?: AxiosTransform;
|
||||||
requestOptions?: RequestOptions;
|
requestOptions?: RequestOptions;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ const transform: AxiosTransform = {
|
|||||||
|
|
||||||
// 请求之前处理config
|
// 请求之前处理config
|
||||||
beforeRequestHook: (config, options) => {
|
beforeRequestHook: (config, options) => {
|
||||||
const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options;
|
const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true,urlPrefix } = options;
|
||||||
|
|
||||||
if (joinPrefix) {
|
if (joinPrefix) {
|
||||||
config.url = `${urlPrefix}${config.url}`;
|
config.url = `${urlPrefix}${config.url}`;
|
||||||
@ -199,8 +199,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
|
|||||||
timeout: 10 * 1000,
|
timeout: 10 * 1000,
|
||||||
// 基础接口地址
|
// 基础接口地址
|
||||||
// baseURL: globSetting.apiUrl,
|
// baseURL: globSetting.apiUrl,
|
||||||
// 接口可能会有通用的地址部分,可以统一抽取出来
|
|
||||||
urlPrefix: urlPrefix,
|
|
||||||
headers: { 'Content-Type': ContentTypeEnum.JSON },
|
headers: { 'Content-Type': ContentTypeEnum.JSON },
|
||||||
// 如果是form-data格式
|
// 如果是form-data格式
|
||||||
// headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
|
// headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
|
||||||
@ -222,6 +221,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
|
|||||||
errorMessageMode: 'message',
|
errorMessageMode: 'message',
|
||||||
// 接口地址
|
// 接口地址
|
||||||
apiUrl: globSetting.apiUrl,
|
apiUrl: globSetting.apiUrl,
|
||||||
|
// 接口拼接地址
|
||||||
|
urlPrefix: urlPrefix,
|
||||||
// 是否加入时间戳
|
// 是否加入时间戳
|
||||||
joinTime: true,
|
joinTime: true,
|
||||||
// 忽略重复请求
|
// 忽略重复请求
|
||||||
@ -240,5 +241,6 @@ export const defHttp = createAxios();
|
|||||||
// export const otherHttp = createAxios({
|
// export const otherHttp = createAxios({
|
||||||
// requestOptions: {
|
// requestOptions: {
|
||||||
// apiUrl: 'xxx',
|
// apiUrl: 'xxx',
|
||||||
|
// urlPrefix: 'xxx',
|
||||||
// },
|
// },
|
||||||
// });
|
// });
|
||||||
|
2
types/axios.d.ts
vendored
2
types/axios.d.ts
vendored
@ -14,6 +14,8 @@ export interface RequestOptions {
|
|||||||
joinPrefix?: boolean;
|
joinPrefix?: boolean;
|
||||||
// Interface address, use the default apiUrl if you leave it blank
|
// Interface address, use the default apiUrl if you leave it blank
|
||||||
apiUrl?: string;
|
apiUrl?: string;
|
||||||
|
// 请求拼接路径
|
||||||
|
urlPrefix?: string;
|
||||||
// Error message prompt type
|
// Error message prompt type
|
||||||
errorMessageMode?: ErrorMessageMode;
|
errorMessageMode?: ErrorMessageMode;
|
||||||
// Whether to add a timestamp
|
// Whether to add a timestamp
|
||||||
|
Loading…
Reference in New Issue
Block a user