Skip to content

Commit

Permalink
feat(axios): Do you want to return the original response header? For …
Browse files Browse the repository at this point in the history
…example, use this property when you need to get the response header
  • Loading branch information
zuihou committed May 12, 2021
1 parent 2f8b218 commit 56d8af1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/http/axios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const transform: AxiosTransform = {
*/
transformRequestHook: (res: AxiosResponse<Result>, options: RequestOptions) => {
const { t } = useI18n();
const { isTransformRequestResult } = options;
const { isTransformRequestResult, isReturnNativeResponse } = options;
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
if (isReturnNativeResponse) {
return res;
}
// 不进行任何处理,直接返回
// 用于页面代码可能需要直接获取code,data,message这些信息时开启
if (!isTransformRequestResult) {
Expand Down Expand Up @@ -192,6 +196,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
requestOptions: {
// 默认将prefix 添加到url
joinPrefix: true,
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
isReturnNativeResponse: false,
// 需要对返回数据进行处理
isTransformRequestResult: true,
// post请求的时候添加参数到url
Expand Down
2 changes: 2 additions & 0 deletions src/utils/http/axios/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface RequestOptions {
formatDate?: boolean;
// Whether to process the request result
isTransformRequestResult?: boolean;
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
isReturnNativeResponse?: boolean;
// Whether to join url
joinPrefix?: boolean;
// Interface address, use the default apiUrl if you leave it blank
Expand Down

0 comments on commit 56d8af1

Please sign in to comment.