axios使用

1.get请求

axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
另一种写法:
axios.get('/user',{
param:{ID:12345
}}).then(function(response){
console.log(response)
}).catch(function(error){
console.log(error)
})
2.post请求
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
3.并发请求
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) {
    // 两个请求现在都执行完成
  }));
posted @ 2019-09-22 16:04  星雨,恒奋斗,过客  阅读(140)  评论(0编辑  收藏  举报