1.axios并发请求
<script>
axios.all([
axios.get('http://localhost:9999/student/student/getAllStudent'),
axios.get('http://localhost:9999/student/student/findStudentById',{
params:{id:1}
})
]).then(res>{
//请求成功响应的是一个数组
console.log(res[0]);
console.log("=========");
console.log(res[1]);
}).catch(err=>{
console.log(err);
})
</script>
2.使用spread方法处理响应数组结果
<script>
axios.all([
axios.get('http://localhost:9999/student/student/getAllStudent'),
axios.get('http://localhost:9999/student/student/findStudentById',
{
params:{id:1}
})
]).then(
axios.spread((res1,res2)=>{
console.log(res1);
console.log(res2);
})
).catch(err=>{
console.log(err)
})
</script>