V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tao1991123
V2EX  ›  问与答

求推荐一款轻量级 XHR 库

  •  
  •   tao1991123 · 2016-01-08 16:48:34 +08:00 · 3160 次点击
    这是一个创建于 3002 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    注:项目不需要兼容任何 IE ,主要针对 Chrome 以及各种 chrome 壳浏览器
    10 条回复    2016-01-09 10:07:12 +08:00
    thinkif
        1
    thinkif  
       2016-01-08 16:51:16 +08:00
    vue-resource

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

    在用, 挺不错的
    oxyflour
        2
    oxyflour  
       2016-01-08 17:11:51 +08:00
    ChiangDi
        3
    ChiangDi  
       2016-01-08 17:13:11 +08:00
    window.fetch ,在不支持的浏览器上有 polyfill https://github.com/github/fetch
    doublleft
        4
    doublleft  
       2016-01-08 17:17:44 +08:00
    有机关枪不用,非要自己拿刀砍
    oott123
        5
    oott123  
       2016-01-08 17:48:11 +08:00
    非要操作 DOM 还有 v-el 呢。
    xhr 我比较喜欢 axios
    heraldboy
        6
    heraldboy  
       2016-01-08 18:01:20 +08:00
    我总感觉如果不是特别必要,没有必要折腾各种框架。
    loading
        7
    loading  
       2016-01-08 20:22:27 +08:00 via iPhone
    你搜索 jquery 替代,知乎有。
    laiqs2011
        8
    laiqs2011  
       2016-01-08 21:44:03 +08:00   ❤️ 1
    直接使用 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
        9
    alex321  
       2016-01-08 21:56:40 +08:00
    一般工作一段时间的前端都会直接封装好多常用的类库吧,那都是原生的啊。。。
    void1900
        10
    void1900  
       2016-01-09 10:07:12 +08:00
    zepto
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1048 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:35 · PVG 06:35 · LAX 15:35 · JFK 18:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.