axios介绍以及使用流程

axios是一个可以同时在客户端以及node服务端同时使用的ajax库,同时也是vue2.x中推荐使用的ajax库,可以拦截请求和相应、取消请求、同时发起多个请求等操作

使用流程
npm install axios   //下载axios包
发送get请求
//参数直接拼在url后面
axios.get('/getlist?tid=1').then((res)=>{

}).catch((err)=>{

})
//或者另外一种写法
axios.get('/getlist',{
  params:{
    tid:1
  }
}).then((res) =>{

}).catch((res) =>{

})
发送post请求
axios.post('/userinfo',{
  uid:1,
  nick_name:"xxx",
  age:12
}).then((res) =>{

}).catch((err) =>{
})
同时发起多个请求
function getList(){
  return axios.get('/list');
}
function getDetails(){
  return axios.get('/details');
}

axios.all([getList(),getDetails()]).then(axios.spread(acct, perms)=>{
  //两个请求都执行完成后的操作
})

更多配置可以参考axios中文文档