0
我想从具有REST API的不同服务器获取数据。REST Api反应本地获取数据失败
我这样做:
return fetch('http://localhost:9000/processes')
.then((response) => response.json())
.then((responseJson) => {
return responseJson;
})
.catch((error) => {
console.error(error);
});
在渲染功能,我有这样的:
{JSON.stringify(getProcesses().Prozess1) }
这
{JSON.stringify(getProcesses()) }
没有thesse两个例子一个返回的东西
T他REST API应该返回此:
{
"Prozess1": "Hallo ich bin ein Prozess"
}
什么我在这种情况下,问题
'getProcesses()'是异步操作,它返回一个承诺? – Sulthan
是getProcesses ist函数返回json – Felix
fetch()是异步的,所以它不应该返回任何东西。 fetch()。then()是一个承诺,这意味着每当读取完成时,执行以下操作。所以重构一下你的代码 –