1.0.2-test-6 • Published 8 months ago
@xxl-father/baxios v1.0.2-test-6
axios工具
介绍
这个库是一个对axios的二次封装,让请求能够预先定义好,需要发送的时候再使用对应的方法。更好的支持RESTful风格的请求,另外还支持根据自定义响应状态码映射表调用对应的方法
//响应体必须为这种格式 type Data = { data:any code:number msg:string }
## 使用
```js
import { createAxios } form 'baxios'
const config = {
baseURL: location.origin + '/api/',
withCredentials: true,
timeout: 5000
}
// 响应状态码映射
const codeMap = {
'200':"成功",
'404':"没有查询到数据"
}
const request = axios.create(config)
const baxios = createBAxios({
...config
},codeMap)
// 创建请求 未发送 在这里设置完uri 路径过后
let test = baxios("uri")
/**
* 另外baxios 上还可以绑定几个事件
* onErrMsg: (callback: (msg: string) => void) => void;
* onSuccMsg: (callback: (msg: string) => void) => void;
* onReqError: (callback: (err: import('axios').AxiosError) => void) => void;
* onResError: (callback: (err: import('axios').AxiosError) => void) => void;
* **/
// 真实发送 这里的方法不能设置uri 路径
// 返回promise 且若是不报错的话 直接返回response 里的data
test.get()
test.post()
test.postForm()
1.0.2-test-6
8 months ago
1.0.2-test-5
8 months ago
1.0.2-test-4
8 months ago
1.0.2-test-3
8 months ago
1.0.2-test-2
8 months ago
1.0.2-test-1
8 months ago
1.0.2-test
8 months ago
1.0.1
8 months ago
1.0.0
8 months ago