|
@@ -165,6 +165,22 @@ export class VAxios {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ get<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
|
|
|
+ return this.request({ ...config, method: 'GET' }, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ post<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
|
|
|
+ return this.request({ ...config, method: 'POST' }, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ put<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
|
|
|
+ return this.request({ ...config, method: 'PUT' }, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ delete<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
|
|
|
+ return this.request({ ...config, method: 'DELETE' }, options);
|
|
|
+ }
|
|
|
+
|
|
|
request<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T> {
|
|
|
let conf: AxiosRequestConfig = cloneDeep(config);
|
|
|
const transform = this.getTransform();
|
|
@@ -173,7 +189,7 @@ export class VAxios {
|
|
|
|
|
|
const opt: RequestOptions = Object.assign({}, requestOptions, options);
|
|
|
|
|
|
- const { beforeRequestHook, requestCatch, transformRequestData } = transform || {};
|
|
|
+ const { beforeRequestHook, requestCatchHook, transformRequestHook } = transform || {};
|
|
|
if (beforeRequestHook && isFunction(beforeRequestHook)) {
|
|
|
conf = beforeRequestHook(conf, opt);
|
|
|
}
|
|
@@ -183,16 +199,16 @@ export class VAxios {
|
|
|
this.axiosInstance
|
|
|
.request<any, AxiosResponse<Result>>(conf)
|
|
|
.then((res: AxiosResponse<Result>) => {
|
|
|
- if (transformRequestData && isFunction(transformRequestData)) {
|
|
|
- const ret = transformRequestData(res, opt);
|
|
|
+ if (transformRequestHook && isFunction(transformRequestHook)) {
|
|
|
+ const ret = transformRequestHook(res, opt);
|
|
|
ret !== errorResult ? resolve(ret) : reject(new Error('request error!'));
|
|
|
return;
|
|
|
}
|
|
|
resolve((res as unknown) as Promise<T>);
|
|
|
})
|
|
|
.catch((e: Error) => {
|
|
|
- if (requestCatch && isFunction(requestCatch)) {
|
|
|
- reject(requestCatch(e));
|
|
|
+ if (requestCatchHook && isFunction(requestCatchHook)) {
|
|
|
+ reject(requestCatchHook(e));
|
|
|
return;
|
|
|
}
|
|
|
reject(e);
|