Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改axios 中 urlPrefix 字段不生效问题 #1170

Merged
merged 3 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/utils/http/axios/axiosTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { RequestOptions, Result } from '/#/axios';

export interface CreateAxiosOptions extends AxiosRequestConfig {
authenticationScheme?: string;
urlPrefix?: string;
transform?: AxiosTransform;
requestOptions?: RequestOptions;
}
Expand Down
8 changes: 5 additions & 3 deletions src/utils/http/axios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -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 },
Expand All @@ -222,6 +221,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
errorMessageMode: 'message',
// 接口地址
apiUrl: globSetting.apiUrl,
// 接口拼接地址
urlPrefix: urlPrefix,
// 是否加入时间戳
joinTime: true,
// 忽略重复请求
Expand All @@ -240,5 +241,6 @@ export const defHttp = createAxios();
// export const otherHttp = createAxios({
// requestOptions: {
// apiUrl: 'xxx',
// urlPrefix: 'xxx',
// },
// });
2 changes: 2 additions & 0 deletions types/axios.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down