我正在尝试从两个不同的api端点获取数据,并试图在我的React本机应用程序This is the snapshot of the error I'm getting with the code snippet中的同一页面中显示整个数据。>
我正在尝试从两个不同的api端点获取数据,并试图在我的React本机应用程序的同一页面中显示整个数据。这是我通过代码片段得到的错误的快照
fetch(‘endpoint1’, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json'
},
body: JSON.stringify({
//e.g. “id”: this.state.id,
…
})
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource1: responseJson,
dataSource2: responseJson,
})
})
.then(()=>{
fetch(‘endpoint2', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json'
},
body: JSON.stringify({
//send the parameters you need to use to fetch the data from
endpoint
//e.g. “id”: this.state.id,
…
})
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource2: responseJson,
})
})
})
.catch((error) => {
console.error(error);
});