How to return the Promise.all fetch api json data?

前端 未结 5 2187
滥情空心
滥情空心 2021-01-05 15:45

How to I consume the Promise.all fetch api json data? It works fine to pull it if I don\'t use Promise.all. With .all it actually returns the values of the query in the cons

5条回答
  •  半阙折子戏
    2021-01-05 15:59

    Simplest solution is to repeat use of Promise.all, to wait for all .json() to resolve. Just use

    Promise.all([fetch1, ... fetchX])
    .then(result => Promise.all(result.map(v => v.json()))
    .then(result => {... result[0, ...X] available as objects})
    

提交回复
热议问题