0.0.2 • Published 2 years ago

use-axios-http v0.0.2

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

use-axios-http

可配置化的 axios 封装,无需额外封装大量代码,提供 getpost 、上传、下载接口支持,兼容 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);
0.0.2

2 years ago

0.0.1

2 years ago