1.0.5 • Published 3 years ago

asyncres v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

使用Asyncres

  • 接受跨域 cookies
  • 接受自定义请求头 headers:{}

基本的 Asyncres 请求设置起来很简单。看看下面的代码:

import Asyncres from "Asyncres";
Asyncres.get('http://example.com/movies.json').then((res)=> {
    console.log(res);
})
// or 
Asyncres('http://example.com/movies.json', {
	type: "get",
})

请求参数

Asyncres(url,params,chuanshen) 可以接受3个参数

  • url :string 请求地址
  • params : Parames 请求头、请求类型、以及其他的一些参数配置 + {cache: string, headers: Headers, type: string, mode: string} + cache 是否异步 default, no-cache, reload, force-cache, only-if-cached + headers 请求头配置 + type 请求类型配置 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT' + mode 请求方式 no-cors, cors, *same-origin
  • chuanshen:Object | string 请求参数配置(自定义)
Asyncres('http://example.com/movies.json', {
	cache: 'no-cache',
	headers: {
		'cookies': 'AsyncresTestcOOKies',
		'content-type': 'application/json'
	},
	method: 'POST'
	mode: 'cors'
},{
	useId:1
})
// or
Asyncres.post('http://example.com/movies.json', {
	cache: 'no-cache',
	headers: {
		'cookies': 'AsyncresTestcOOKies',
		'content-type': 'application/json'
	}
	mode: 'cors'
},{
	useId:1
})

拦截器

在请求或响应处理前拦截它们。

// 添加请求拦截器
Asyncres.useRequest((state: any) => {
    console.log(state);
});
// 添加响应拦截器
Asyncres.useResponse((state: any) => {
    console.log(state);
});

配置默认值

你可以指定将被用在各个请求的配置默认值

Asyncres.defaults = {
    timeout: 0,
    baseURL: "",
    type: "get",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    }
}
// or
Asyncres.create({
    timeout: 0,
    baseURL: "",
    type: "get",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    }
})

问题反馈

在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago