简体   繁体   English

如何使用ReactJS从多个URL获取数据?

[英]How to get data from multiple URL's using ReactJS?

I have 3 API endpoints and I have made a search box where user inputs search term. 我有3个API端点,并在用户输入搜索词的地方做了一个搜索框。 After typing in the search term in search box all the data from API endpoint should return it. 在搜索框中输入搜索词后,API端点的所有数据都应返回该数据。

API endpoints: API端点:

localhost:5000/mydata1/search/q="searchterm"

localhost:5000/mydata2/search/q="searchterm

localhost:5000/mydata3/search/q="searchterm"

Now above our 3 API endpoints. 现在在我们的3个API端点之上。 When I type in some search term in search box it should display all the data from API endpoints. 当我在搜索框中输入某个搜索词时,它应该显示来自API端点的所有数据。 As I am new to ReactJS I want to ask to get the data (JSON response) from API endpoints do I need to call fetch() on each URL's to get the data or is there some other efficient way to do it. 由于我是ReactJS的新手,我想问一下从API端点获取数据(JSON响应)的过程,我是否需要在每个URL上调用fetch()来获取数据,或者是否有其他有效的方法来做到这一点?

You can use bluebirds Promise.all. 您可以使用蓝鸟Promise.all。 Documentation . 文件资料 This will wait for any number of calls to finish before providing a response object. 在提供响应对象之前,它将等待任何数量的调用完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM