【发布时间】:2021-02-21 16:15:29
【问题描述】:
对于我的项目,我必须在我的项目中获取多个 API,这些 API 与其他 API 相关联,即它们具有相同的数据...
这是我的代码
export default class App extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
Promise.all([
getData(),
getData('?page=2'),
])
.then(([dataSource1, dataSource2]) => {
this.setState({
isLoading: false,
isLoading2: false,
dataSource1,
dataSource2,
});
})
.catch((error) => {
// handle errors
});
}
render() {
const getData = (subpath = '') => fetch(`https://api.rawg.io/api/games${subpath}`)
.then(res => res.json())
.then(result => result.results);
console.log(getData)
}
我尝试使用 axios 但没有成功...
当我删除评论时,它只显示第二次提取...
【问题讨论】:
-
您能否详细说明您的意思,获取多个 api 的?
-
请提及 API 是如何相互链接的。提供的示例几乎没有解释任何内容。
标签: javascript reactjs react-native get fetch