1.5.3-alpha.2 • Published 1 year ago

@wya/http v1.5.3-alpha.2

Weekly downloads
1
License
MIT
Repository
github
Last release
1 year ago

\@wya/http

npm changelog

安装

npm install @wya/http --save

用法例子

import createHttpClient, { ajax } from '@wya/http';

let cancelCb;

ajax({
	url: 'http://***.com/{id}?userName={user.name}', // 支持动态路由
	type: "GET",
	param: {
		id: '2',
		user: {
			name: 'wya-team',
			age: ''
		}
	},
	requestType: "form-data:json",
	getInstance: ({ xhr, cancel }) => cancelCb = cancel,
	debug: true
}).then((res) => {
	console.log(res, 0);
}).catch((res) => {
	console.log(res);
});

setTimeout(() => {
	cancelCb();
}, 100);

API

属性说明类型默认值
createHttpClient注册函数(globalOptions = {}) => Func-
ajaxajax函数(userOptions = {}) => Promise-
const { ajax } = createHttpClient();
  • createHttpClient - 参数说明
属性说明类型默认值
globalOptions可以给下面的userOptions设置些默认值obj-
  • 参数配置原则: userOptions(single) > registerOptions(HOF) > defaultOptions(single)

  • ajax - 参数说明 - 属性

属性说明类型默认值
url请求地址pathstr-
type请求类型strGET
param参数obj-
async请求是否是异步booltrue
debug测试boolfalse
requestTypeform-datajsonform-data:json(POST方式以 data: JSON.stringify(data)传递)strform-data
allowEmptyString是否接收空字符串boolfalse
loading执行loadingFnloadedFnbooleantrue
localData假如数据有缓存,不请求ajaxobj-
apis---
responseType---
credentials---
headers---
useXHR---
restful---
timeout单位s--
delay单位s--
  • ajax - 参数说明 - 方法
属性说明类型默认值
onLoading请求时回调({ options }) => void-
onLoaded请求完回调,可以把loading移除({ options }) => void-
onBefore在调用前改变options - 拦截options({ options }) => Promise-
onAfter在调用后改变response - 拦截response({ response, options }) => Promise-
onOtherstatus !1或!0,以外的情({ response, options }) => void-
onProgress上传进度回调(e) => void-
getInstance获取XHR实例({ xhr, options, cancel }) => void-
1.5.3-alpha.2

1 year ago

1.5.3-alpha.1

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.2-alpha.1

2 years ago

1.5.0

3 years ago

1.5.0-alpha.1

4 years ago

1.5.0-alpha.2

4 years ago

1.5.0-alpha.0

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago