首页 > 移动平台 > 详细

axios请求使用

时间:2021-09-07 16:25:46      阅读:36      评论:0      收藏:0      [点我收藏+]

首先进行安装axios

可以使用 yarn安装  命令如下: yarn add axios

执行get请求

axios.get(‘/user‘,{
params:{ id:13}

}).then(function (response) {

console.log(response)  

}).catch(function (err)

{

console.log(err)
})

 

执行 POST 请求

axios.post(‘/user‘, {
firstName: ‘Fred‘,
lastName: ‘Flintstone‘
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});

执行多个并发请求

function getUserAccount() {
return axios.get(‘/user/12345‘);
}

function getUserPermissions() {
return axios.get(‘/user/12345/permissions‘);
}

axios.all([getUserAccount(), getUserPermissions()])
.then(axios.spread(function (acct, perms) {
// 两个请求现在都执行完成
}));

axios请求使用

原文:https://www.cnblogs.com/luhan930/p/15236467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!