Commit d5f9919b60fdd7d5c435129e8db519c0bbd37529

Authored by JinMao
1 parent aed622bd

fix: fix defHttp baseUrl work

Showing 1 changed file with 5 additions and 1 deletions
src/utils/http/axios/index.ts
... ... @@ -80,6 +80,7 @@ const transform: AxiosTransform = {
80 80  
81 81 // 请求之前处理config
82 82 beforeRequestHook: (config, options) => {
  83 + const { baseURL } = config;
83 84 const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options;
84 85  
85 86 if (joinPrefix) {
... ... @@ -89,6 +90,9 @@ const transform: AxiosTransform = {
89 90 if (apiUrl && isString(apiUrl)) {
90 91 config.url = `${apiUrl}${config.url}`;
91 92 }
  93 + if (baseURL && isString(baseURL)) {
  94 + config.url = `${baseURL}${config.url}`;
  95 + }
92 96 const params = config.params || {};
93 97 if (config.method?.toUpperCase() === RequestEnum.GET) {
94 98 if (!isString(params)) {
... ... @@ -186,7 +190,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
186 190 authenticationScheme: '',
187 191 timeout: 10 * 1000,
188 192 // 基础接口地址
189   - // baseURL: globSetting.apiUrl,
  193 + baseURL: globSetting.apiUrl,
190 194 // 接口可能会有通用的地址部分,可以统一抽取出来
191 195 urlPrefix: urlPrefix,
192 196 headers: { 'Content-Type': ContentTypeEnum.JSON },
... ...