xnsk-mini-http
v0.0.1-rc5
Published
基于axios的迷你网络处理,专为xnsk平台使用
Downloads
7
Readme
安装:
npm i xnsk-mini-http
配置
//统一配置
import useMiniHttp from "xnsk-mini-http"
const config = {
baseURL:"",//请求前缀
beforeRequest:(request, extendsConfig)=>{
//请求前拦截,如添加token,设置Content-Type等
},
onNetWorkError:(response, extendsConfig)=>{
//网络层错误,统一处理一下
},
onError:(res, extendsConfig)=>{
//业务层错误,统一处理一下
}
}
const http = useMiniHttp(config);
//或者
const miniHttp = useMiniHttp();
const http = miniHttp.create(config);
export default http
//extendsConfig 是扩展字段,可以随意定制
使用
import http from "xxx";//上面那个配置文件的路径
http("base_curr_user_info")({key:123});//前面()生成一个post方法,后面()用来传参数,如果没有参数,可以直接写()
说明:
- 仅支持post 请求
- 可以在第一个()中传入第二个参数作为扩展字段,即 extendsConfig,想写啥都可以,自己去解析。比如上传接口:
http("upload",{
"Content-Type":"multipart/form-data;charset=UTF-8"
})(formData)