feat(axios): Do you want to return the original response header? For example, use this property when you need to get the response header

This commit is contained in:
zuihou 2021-05-12 13:19:14 +08:00
parent 2f8b2183ec
commit 56d8af147e
2 changed files with 9 additions and 1 deletions

View File

@ -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;
}
// 不进行任何处理,直接返回
// 用于页面代码可能需要直接获取codedatamessage这些信息时开启
if (!isTransformRequestResult) {
@ -192,6 +196,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
requestOptions: {
// 默认将prefix 添加到url
joinPrefix: true,
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
isReturnNativeResponse: false,
// 需要对返回数据进行处理
isTransformRequestResult: true,
// post请求的时候添加参数到url

View File

@ -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