axios易用、简洁且高效的http库
作者:Alpha时间:2020-12-20 阅读数:2551 +人阅读
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。
1、支持node端和浏览器端--同样的API,node和浏览器全支持,平台切换无压力;
2、支持 Promise--使用Promise管理异步,告别传统callback方式
3、丰富的配置项--支持拦截器等高级配置
4、社区支持--axios相关的npm包数量一直在增长
安装:
npm install axios
vue cli3.x也可以使用下面的命令进行安装
vue add axios
具体的使用方法可以参考官方文档,这里只是记录下:
执行 GET 请求 :
axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
执行 POST 请求 :
axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
上面是基础的用法,当然相比ajax,也有更高级的用法。
本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。
如果侵犯了你的权益请来信告知我们删除。邮箱:595397166@qq.com