sasai-axios
v1.0.0
Published
My webpack project
Downloads
4
Readme
Axios 封装
导语
普通的项目直接使用 Axios 已经是足够的,但是相对复杂的项目,尤其是使用不同的后端服务,axios需要针对于不同的服务做出不同的配置或者处理, 就需要创建多个axios,简单粗暴的同学会多复制一份axios.js,这样能处理问题,但是不符合编程思想,所以使用类语法进行封装,来创建多个实例,一套代码传入不同配置来应对不同的需求
JS版本1.0
- 可创建多个axios实例, 实现多个实例不同, 支持传入配置 baseURL默认接口地址, timeout超时时间
- 增加请求优化配置 clear是否取消重复请求,同一时间内同个接口 如果在 pending 中则取消之前的请求
- 抛出了 clearPending 方法 清空 pending 中的请求(在路由跳转时调用)优化请求带宽
TS版本1.0 (主要参考网上代码,以及代码解析)
- 可创建多个axios实例, 实现多个实例不同, 支持传入配置 axios 所有支持的配置,并支持手动传入自定义拦截器
- 拦截器更加灵活,有全局、实例、接口三种拦截器。
- 增加请求优化配置 可以移除请求
- TS语法,代码更加规范化,减少运行错误发生