vue使用axios

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
}));

 

posted @ 2018-11-17 23:33  Jin同学  阅读(96)  评论(0)    收藏  举报