求推荐一款轻量级 XHR 库

2016-01-08 16:48:34 +08:00
 tao1991123

原来一直用 jQuery 。
最近上手 Vue.js ,感觉特爽。
可以部分脱离 jQuery 了。
非要直接操作 DOM 的 原生的 queryselector 感觉也够用了。
现在只剩下 XHR 这部分了,感觉不太喜欢 ES5 原生的。
所以求一个和 vuejs 配合使用的轻量 XHR js 库

注:项目不需要兼容任何 IE ,主要针对 Chrome 以及各种 chrome 壳浏览器
3200 次点击
所在节点    问与答
10 条回复
thinkif
2016-01-08 16:51:16 +08:00
vue-resource

https://github.com/vuejs/vue-resource

在用, 挺不错的
oxyflour
2016-01-08 17:11:51 +08:00
ChiangDi
2016-01-08 17:13:11 +08:00
window.fetch ,在不支持的浏览器上有 polyfill https://github.com/github/fetch
doublleft
2016-01-08 17:17:44 +08:00
有机关枪不用,非要自己拿刀砍
oott123
2016-01-08 17:48:11 +08:00
非要操作 DOM 还有 v-el 呢。
xhr 我比较喜欢 axios
heraldboy
2016-01-08 18:01:20 +08:00
我总感觉如果不是特别必要,没有必要折腾各种框架。
loading
2016-01-08 20:22:27 +08:00
你搜索 jquery 替代,知乎有。
laiqs2011
2016-01-08 21:44:03 +08:00
直接使用 fetch API 不就足够了?

类似这样:

fetch(`/api/resource/xxxxx`, {
method: 'get',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(res => {
return res.json();
}).then(json => {
console.log('result', result);
}
}).catch(error => {
console.log('error: ', error);
});

只兼容 chrome 的话,这么写是很爽的。

[https://github.com/github/fetch]( https://github.com/github/fetch)
alex321
2016-01-08 21:56:40 +08:00
一般工作一段时间的前端都会直接封装好多常用的类库吧,那都是原生的啊。。。
void1900
2016-01-09 10:07:12 +08:00
zepto

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/249334

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX