1,使用一个 GET 请求
//发起一个user请求,参数为给定的ID
axios.get('/user?ID=1234')
.then(function(respone){
console.log(response);
})
.catch(function(error){
console.log(error);
});
//上面的请求也可选择下面的方式来写
axios.get('/user',{
params:{
ID:12345
}
})
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error)
});
2,发起一个 POST 请求
axios.post('/user',{
firstName:'friend',
lastName:'Flintstone'
})
.then( function( response ){
console.log( response );
})
.catch(function(error){
console.log(error)
;});
3,发起一个多重并发请求
functiongetUserAccount(){
returnaxios.get('/user/12345');
}
functiongetUserPermissions(){
returnaxios.get('/user/12345/permissions');
}
axios.all([getUerAccount(),getUserPermissions()])
.then(axios.spread(function(acc,pers){
//两个请求现在都完成
}));
网友评论