Commit 56d8af147ec88bb98a37fa3ddf47c2aa16a4110e
1 parent
2f8b2183
feat(axios): Do you want to return the original response header? For example, us…
…e this property when you need to get the response header
Showing
2 changed files
with
9 additions
and
1 deletions
src/utils/http/axios/index.ts
... | ... | @@ -35,7 +35,11 @@ const transform: AxiosTransform = { |
35 | 35 | */ |
36 | 36 | transformRequestHook: (res: AxiosResponse<Result>, options: RequestOptions) => { |
37 | 37 | const { t } = useI18n(); |
38 | - const { isTransformRequestResult } = options; | |
38 | + const { isTransformRequestResult, isReturnNativeResponse } = options; | |
39 | + // 是否返回原生响应头 比如:需要获取响应头时使用该属性 | |
40 | + if (isReturnNativeResponse) { | |
41 | + return res; | |
42 | + } | |
39 | 43 | // 不进行任何处理,直接返回 |
40 | 44 | // 用于页面代码可能需要直接获取code,data,message这些信息时开启 |
41 | 45 | if (!isTransformRequestResult) { |
... | ... | @@ -192,6 +196,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) { |
192 | 196 | requestOptions: { |
193 | 197 | // 默认将prefix 添加到url |
194 | 198 | joinPrefix: true, |
199 | + // 是否返回原生响应头 比如:需要获取响应头时使用该属性 | |
200 | + isReturnNativeResponse: false, | |
195 | 201 | // 需要对返回数据进行处理 |
196 | 202 | isTransformRequestResult: true, |
197 | 203 | // post请求的时候添加参数到url | ... | ... |
src/utils/http/axios/types.ts
... | ... | @@ -7,6 +7,8 @@ export interface RequestOptions { |
7 | 7 | formatDate?: boolean; |
8 | 8 | // Whether to process the request result |
9 | 9 | isTransformRequestResult?: boolean; |
10 | + // 是否返回原生响应头 比如:需要获取响应头时使用该属性 | |
11 | + isReturnNativeResponse?: boolean; | |
10 | 12 | // Whether to join url |
11 | 13 | joinPrefix?: boolean; |
12 | 14 | // Interface address, use the default apiUrl if you leave it blank | ... | ... |