@@ -8,6 +8,8 @@ import { cloneDeep } from 'lodash-es';
88import type { RequestOptions , CreateAxiosOptions , Result , UploadFileParams } from './types' ;
99import { errorResult } from './const' ;
1010import { ContentTypeEnum } from '/@/enums/httpEnum' ;
11+ import qs from 'qs' ;
12+ import { RequestEnum } from '../../../enums/httpEnum' ;
1113
1214export * from './axiosTransform' ;
1315
@@ -144,6 +146,25 @@ export class VAxios {
144146 } ) ;
145147 }
146148
149+ // support form-data
150+ supportFormData ( config : AxiosRequestConfig ) {
151+ const headers = this . options ?. headers ;
152+ const contentType = headers ?. [ 'Content-Type' ] || headers ?. [ 'content-type' ] ;
153+
154+ if (
155+ contentType !== ContentTypeEnum . FORM_URLENCODED ||
156+ ! Reflect . has ( config , 'data' ) ||
157+ config . method ?. toUpperCase ( ) === RequestEnum . GET
158+ ) {
159+ return config ;
160+ }
161+
162+ return {
163+ ...config ,
164+ data : qs . stringify ( config . data ) ,
165+ } ;
166+ }
167+
147168 request < T = any > ( config : AxiosRequestConfig , options ?: RequestOptions ) : Promise < T > {
148169 let conf : AxiosRequestConfig = cloneDeep ( config ) ;
149170 const transform = this . getTransform ( ) ;
@@ -156,6 +177,8 @@ export class VAxios {
156177 if ( beforeRequestHook && isFunction ( beforeRequestHook ) ) {
157178 conf = beforeRequestHook ( conf , opt ) ;
158179 }
180+
181+ conf = this . supportFormData ( conf ) ;
159182 return new Promise ( ( resolve , reject ) => {
160183 this . axiosInstance
161184 . request < any , AxiosResponse < Result > > ( conf )
0 commit comments