axios并发请求

方式一

<script>
    axios([
        axios.get('http://localhost:8080/student/getAllStudent'),
        axios.post('http://localhost:8080/student/getStudentById',{id:1})
    ]).then(res=>{//请求成功相应的是一个数组
        console.log(res[0]);
        console.log(res[1]);
    });
</script>

  

方式二(使用spread方法处理相应数组结果)

<script>
    axios([
        axios.get('http://localhost:8080/student/getAllStudent'),
        axios.post('http://localhost:8080/student/getStudentById',{id:1})
    ]).then(
        axios.spread((res1,res2)=>{
            console.log(res1);
            console.log(res2);
        })
    );
</script>

  

<script>
    axios([
        axios.get('http://localhost:8080/student/getAllStudent'),
        axios.post('http://localhost:8080/student/getStudentById',{id:1})
    ]).then(res=>{
        console.log(res[0]);
        console.log(res[1]);
    });
</script>
posted @ 2020-12-24 07:48  Mr_sven  阅读(115)  评论(0编辑  收藏  举报