Skip to content

Commit

Permalink
fix: fix defHttp baseUrl work
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmao88 committed Jun 25, 2021
1 parent aed622b commit d5f9919
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/http/axios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const transform: AxiosTransform = {

// 请求之前处理config
beforeRequestHook: (config, options) => {
const { baseURL } = config;
const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options;

if (joinPrefix) {
Expand All @@ -89,6 +90,9 @@ const transform: AxiosTransform = {
if (apiUrl && isString(apiUrl)) {
config.url = `${apiUrl}${config.url}`;
}
if (baseURL && isString(baseURL)) {
config.url = `${baseURL}${config.url}`;
}
const params = config.params || {};
if (config.method?.toUpperCase() === RequestEnum.GET) {
if (!isString(params)) {
Expand Down Expand Up @@ -186,7 +190,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
authenticationScheme: '',
timeout: 10 * 1000,
// 基础接口地址
// baseURL: globSetting.apiUrl,
baseURL: globSetting.apiUrl,
// 接口可能会有通用的地址部分,可以统一抽取出来
urlPrefix: urlPrefix,
headers: { 'Content-Type': ContentTypeEnum.JSON },
Expand Down

0 comments on commit d5f9919

Please sign in to comment.