Explorar el Código

优化urlPrefix和url的拼接方法

louhangfei hace 2 años
padre
commit
e66078903c
Se han modificado 1 ficheros con 3 adiciones y 1 borrados
  1. 3 1
      src/utils/http/axios/index.ts

+ 3 - 1
src/utils/http/axios/index.ts

@@ -17,6 +17,7 @@ import { setObjToUrlParams } from '@/utils/urlUtils';
 import { RequestOptions, Result, CreateAxiosOptions } from './types';
 
 import { useUserStoreWidthOut } from '@/store/modules/user';
+import urlJoin from 'url-join';
 
 const globSetting = useGlobSetting();
 const urlPrefix = globSetting.urlPrefix || '';
@@ -140,7 +141,8 @@ const transform: AxiosTransform = {
     const isUrlStr = isUrl(config.url as string);
 
     if (!isUrlStr && joinPrefix) {
-      config.url = `${urlPrefix}${config.url}`;
+      // 这里做兼容
+      config.url = urlJoin(urlPrefix || '', config.url as string);
     }
 
     if (!isUrlStr && apiUrl && isString(apiUrl)) {