我正在开发一些从一个站点中删除一些数据的服务。(函数getLinks()将所需数据添加到全局数组results1 []并且它工作正常) 之后我想使用React Component渲染这个数据。
class Page extends React.Component {
constructor(props) {
getLink();
super(props);
this.content = results1[1];
}
但构造函数不会在数据准备好后等待。我尝试过不同的方法来解决这个问题。请任何面临同样问题的人。帮帮我
答案 0 :(得分:1)
Web抓取在JavaScript中是异步的,您应该在服务器返回数据时添加回调,或者最好使用promises。使用获取API的示例:https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch