vue axios

vue axios

vue2.0之后,就不再对vue-resource更新,而是推荐使用axios。基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 Node.js 中使用。

功能特性

1、在浏览器中发送 XMLHttpRequests 请求

2、在 node.js 中发送 http请求

3、支持 Promise API

4、拦截请求和响应

5、转换请求和响应数据

6、取消请求

7、自动转换 JSON 数据

8、客户端支持保护安全免受 CSRF/XSRF 攻击

安装 axios

$ npm install axios

在要使用的文件中引入axios

import axios from 'axios'

GET请求

// 向具有指定ID的用户发出请求axios.get('/user?ID=12345').then(function(response){console.log(response);}).catch(function(error){console.log(error);});// 也可以通过 params 对象传递参数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);});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值