use-axios-http
v0.0.4
Published
可配置化的 axios 封装,无需额外封装大量代码,提供 `get`、`post` 、上传、下载接口支持,兼容 TypeScript.
Downloads
4
Readme
use-axios-http
可配置化的 axios 封装,无需额外封装大量代码,提供 get
、post
、上传、下载接口支持,兼容 TypeScript.
import AxiosHttp, {defineConfig} from "use-axios-http";
import {AxiosError} from "axios";
type RequestData = {
token: string;
};
type ResponseDataWrapper<T = any> = {
data: T;
code: number;
msg: string;
};
const config = defineConfig<RequestData, ResponseDataWrapper>({
config: {
// 支持 axios 的所有配置
baseURL: '',
},
interceptors: {
request: {
onFulfilled: (config) => {
return config
},
onRejected: (error: any) => {
return Promise.reject(error)
},
},
response: {
onFulfilled: (config) => {
return config
},
onRejected: (error: AxiosError) => {
return error
},
},
},
});
const http = new AxiosHttp(config);