2.3.9-temp • Published 9 months ago

@wbiokr/http v2.3.9-temp

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

1 参数

PropertyType默认值Description是否必填
baseURLString''axios实例基础地质当不存在环境变量的时候必填
timeoutNumber0超时时间false
headersObject{}公共headersfalse
commonParamsObject{}公共参数false
dataKeyStringdata响应内容主体false
beforeRequestnullFunction(config)null发起请求之前的配置处理钩子false
errornullFunction(msg)null200但响应内容为错误状态下的错误内容提示false
logoutnullFunction(config)null错误码401时候的退出登录钩子false
isOknullFunction(config)null验证响应内容是否为正确状态,默认匹配code、status是否为200或0false
环境变量: 仅支持webpack环境
VUE环境变量:baseURL---VUE_APP_BASEURL teimout---VUE_APP_TIMEOUT
REACT环境变量:baseURL---REACT_APP_BASEURL teimout---REACT_APP_TIMEOUT

2 发送带取消的请求

2.1 如何发送请求

发送请求的时候,带cancelToken参数: post:请求可以使用Symbol; get:则可以使用时间搓;

2.2 如获取并取消请求

所有带有取消头的请求都会缓存在全局对象window.AXIOS_CANCELS下,使用传入的cancelToken则可以获取到取消函数,手动取消请求:

const cancelPostList = Symbol()
.......// 逻辑代码
window.AXIOS_CANCELS[cancelPostList] && window.AXIOS_CANCELS[cancelPostList]()

3 实例方法

API参数备注
get(url, params, headers)必填url
post(url, data, params, headers)必填url, params为query参数,data为body参数
postWWW(url, data, params)必填url, params为query参数,data为body参数,headers会传入('Content-Type': 'application/x-www-form-urlencoded')
postJson(url, data, params)必填url, params为query参数,data为body参数,headers会传入('Content-Type': 'application/json')
postForm(url, data, params)必填url, params为query参数,data为body参数,headers会传入('Content-Type': 'multipart/form-data')
put(url, data, params, headers)必填url, params为query参数,data为body参数
deleteAction(url, data, params, headers)必填url, params为query参数,data为body参数
getBlob(url, params, headers)必填url, responseType: 'blob'
postBlob(url, data, params, headers)必填url, responseType: 'blob'
download(url, params, type='get', nameOrKey, headers)必填url, 当nameOrKey为完整的的名字时则作为名字下载,无值时取接口filename,有值无后缀时作为key取接口
2.3.9-temp

9 months ago

2.4.1

10 months ago

2.4.0

10 months ago

2.4.3

10 months ago

2.4.2

10 months ago

2.4.4

10 months ago

2.3.8

12 months ago

2.3.7

1 year ago

2.3.9

12 months ago

2.3.4

1 year ago

2.3.3

1 year ago

2.3.6

1 year ago

2.3.5

1 year ago

2.3.5-beta

1 year ago

2.3.2

1 year ago

2.3.1-temp

1 year ago

2.3.0

1 year ago

2.3.1

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

2.0.0

1 year ago

0.0.1

1 year ago