xr是XMLHttpRequest的超简单封装,并返回ES6Promise。
示例代码:
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); } }});
评论