xr-httpXHR 的简单封装
xr 是 XMLHttpRequest 的超简单封装,并返回 ES6 Promise。
示例代码:
xr.get('/api/items', {take: 5})
.then(res => console.log(res.data));
xr.post('/api/item', {name: 'hello'})
.then(res => console.log("new item", res.data));
xr({
method: xr.Methods.GET,
url: '/api/items',
params: {take: 5},
events: {
progress: (xhr, xhrProgressEvent) => {
console.log("xhr", xhr);
console.log("progress", xhrProgressEvent);
}
}
});评论
