Axios之并发请求

场景 :一个页面的数据来源于多个互不关联请求,需要统一处理然后呈现。

需要用Axios的一对API:
1.axios.all(iterable)
2.axios.spread(callback)

- .axios.all(iterable)
    - 参数: 请求数组
- axios.spread(callback)
    - 参数: 对应请求返回值
axios.all(
    [
        axios.get('/test1'),
        axios.get('/test2')
    ]
).then(
    axios.spread( (test1Res,test2Res) => {
        console.log(test1Res,test2Res)    
    })
)

猜你喜欢

转载自www.cnblogs.com/gongxiansheng/p/11258274.html