阅读 87

axios请求使用

首先进行安装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) {
// 两个请求现在都执行完成
}));

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

文章分类
代码人生
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐