Fetch API requesting multiple get requests

后端 未结 4 1214
抹茶落季
抹茶落季 2020-12-07 18:18

I would like to know how to fetch multiple GET URLs at once and then put the fetched JSON data into my React DOM element.

Here is my code:



        
4条回答
  •  时光说笑
    2020-12-07 18:34

    I needed the json format response so I added a little bit of code myself

    Promise.all([
                fetch(url1).then(value => value.json()),
                fetch(url2).then(value => value.json())
                ])
                .then((value) => {
                   console.log(value)
                  //json response
                })
                .catch((err) => {
                    console.log(err);
                });
    

提交回复
热议问题