.then(res=>{},err=>{})
==
.catch(err=>{ throw new Error(err) })
执行 GET 请求
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch((error)=> {
console.log(error);
});
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
执行 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(res) {
console.log(res[0])
console.log(res[1])
}));