安装
使用 npm:
$ npm install axios
使用 bower:
$ bower install axios
使用 cdn:
<scriptsrc=”https://unpkg.com/axios/dist/axios.min.js”></script>
GET请求
为给定 ID 的 user 创建请求
axios.get( /url?ID=123 ).then(function(event){
console.log( event)
}).catch(function(error){
console.log( error )
})
可选地,上面的请求可以这样做
axios.get( /user ,{
params:{ ID:123 }
}).then(function(event){
console.log( event )
}).catch(function(error){
console.log( error )
})
POST请求
axios.post( /user ,{
ID:123,
name: qwex
}).then(function(event){
console.log( event )
}).catch(function(error){
console.log( error )
})
执行多个并发请求
function a(){
return axios.get( /aaa )
}
function b(){
return aixos.get( /bbb )
}
axios.all([a(),b()]).then(axios.spread(function(eventa,eventb){
//目前是两个请求都执行完成了
console.log(eventa,eventb)
}))
