0.0.1-rc5 • Published 9 months ago

xnsk-mini-http v0.0.1-rc5

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

安装:

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方法,后面()用来传参数,如果没有参数,可以直接写()

说明: 1. 仅支持post 请求 2. 可以在第一个()中传入第二个参数作为扩展字段,即 extendsConfig,想写啥都可以,自己去解析。比如上传接口:

http("upload",{
"Content-Type":"multipart/form-data;charset=UTF-8"
})(formData)
0.0.1-rc5

9 months ago

0.0.1-rc4

9 months ago

0.0.1-rc3

9 months ago

0.0.1-rc2

9 months ago

0.0.1-rc1

10 months ago