基于 axios 进行二次封装, 支持 TS
Using npm:
$ npm i cover-axios
Using yarn:
$ yarn add cover-axios
Using pnpm:
$ pnpm i cover-axios
import http, { genApi, addApi, addApiList, request } from 'cover-axios'
const api = genApi('login', 'api/user/login', 'POST')
http.addApi(api)
// or
http.addApiList([api])
const res = await http.request('login', { user: 'user1', password: 123456 })
const res = await request('login', { user: 'user1', password: 123456 })
Requests can be made by passing the relevant config to axios.
延用 axios 的拦截器
http.interceptors.request.use(requestIntercept, requestFail)
http.interceptors.response.use(responentIntercept, requestFail)