我认为问题是值仍然为空我需要设置值,但我不知道如何。我的API可以读取,但我不能输出react.js
constructor() {
super();
this.state = {
jsonReturnedValue: null
}
}
在这方面我设置了一个空值和
试图获取到我的反应,但是当我运行它只有“员工列表”可以看出
fetch("http://localhost:5118/api/employeedetails/getemployeedetails")
.then(handleErrors)
.then(response => response.json()) .then(json => {
this.setState({ jsonReturnedValue: response.results });
}).catch(function(error) {
console.log(error);
});
}
}
render() {
return(
<div>
<h1> Listof Employees </h1>
<h1>{ this.state.jsonReturnedValue }</h1>
</div>
没有获得响应你。然后,但json,console.log(json)在.then回调,然后你可以看到你想要设置为jsonReturnedValue –