Axios 是基于promise 的HTTP库(可在浏览器和node.js中)
特征:
1. 浏览器中创建XMLHttpRequests
2. node.js创建http请求
3. 拦截请求和响应
4. 客户端支持防御XSRF
5....(详细的自己看文档说明)
使用:
GET 请求
//get 方式的参数
//axios.get('/url',{params:{key1:value1}})
axios.get('/url?data=666')
.then(function(msg){})
.catch(function(err){console.log(err)})
POST请求
axios.post('/url',{
key1:value1,
key2:value2
})
.then(function(msg){})
.catch(function(err){console.log(err)})
多个请求并发
axios.all([fun1(), fun2()])
.then(axios.spread(function (acct, perms) {
// 两个请求现在都执行完成
}));
创建实例:
var instance = axios.create({})
实例方法
axios.create({})
…待续