use-axios-http
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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);

Readme

Keywords

none

Package Sidebar

Install

npm i use-axios-http

Weekly Downloads

1

Version

0.0.4

License

none

Unpacked Size

9.29 kB

Total Files

8

Last publish

Collaborators

  • a781278657