GET
axios.get(url).then(function(response){
// 请求成功
const result = response.data;
}).catch(function(error){
// 请求失败
alert(‘请求失败’);
});
POST
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
}).then(function (response) {
console.log(response);
}).catch(function (response) {
console.log(response);
});
发送多个并发请求
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) {
// Both requests are now complete
}));