axios

作者: 是归人不是过客 | 来源:发表于2018-07-26 10:34 被阅读0次

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){ 

     //两个请求现在都完成 

 }));

相关文章

网友评论

    本文标题:axios

    本文链接:https://www.haomeiwen.com/subject/joivmftx.html