app-lib-request
v1.0.14
Published
数据交互
Downloads
224
Maintainers
Readme
二、功能描述
- 基于axios
- 支持es和nodejs
三、注意事项
常见问题 请求跨越
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
原因 请求头里的Host与Origin不一致 baseURL 设置了跨越
Host:172.17.160.184:30201 Origin:http://localhost:3334处理方式
baseURL 往往设置作用于本工程的数据交互与其他静态文件等分开 用于便捷代理到后端服务
六、API
Constants
Functions
CONFIG
配置信息
Kind: global constant
getConfig ⇒ Obejct
获取当前数据交互的配置
- 不存在配置 则采用默认配置
Kind: global constant
Returns: Obejct - axios 配置信息
interceptors
拦截器
interceptors.request.use(function (config) {
// 在发送请求之前做些什么
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});interceptors.response.use(function (response) {
// 2xx 范围内的状态码都会触发该函数。
// 对响应数据做点什么
return response;
}, function (error) {
// 超出 2xx 范围的状态码都会触发该函数。
// 对响应错误做点什么
return Promise.reject(error);
});Kind: global constant
paramsSerializer(params)
过滤空参数
Kind: global function
| Param | Type | Description | | --- | --- | --- | | params | Object | 参数对象 |
bindMock(axiosConfig)
调整mock请求数据
Kind: global function
| Param | Type | | --- | --- | | axiosConfig | Object |
request(config) ⇒ Promise
完整的数据请求
- 所有的便捷请求都会通过该请求
Kind: global function
Returns: Promise - Promise
| Param | Type | Description | | --- | --- | --- | | config | object | 请求配置 |
get(url, params, options) ⇒ Promise
get 请求
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | params | object | 参数 | | options | object | 配置 |
post(url, body, options) ⇒ Promise
post 请求
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
put(url, body, options) ⇒ Promise
put 请求
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
patch(url, body, options) ⇒ Promise
patch 请求
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
del(url, body, options) ⇒ Promise
del 请求
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
head(url, body, options) ⇒ Promise
head 请求
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
copy(url, body, options) ⇒ Promise
copy 请求【axios 未实现 TODO 扩展】
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
upload(url, body, options) ⇒ Promise
upload 上传 [TODO]
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
download(url, body, options) ⇒ Promise
下载 TODO
- 直接url地址
- 流的形式
Kind: global function
Returns: Promise - 异步请求对象
| Param | Type | Description | | --- | --- | --- | | url | string | url地址 | | body | object | 请求体 | | options | object | 配置 |
