为什么不想显示我的数据表?
我不明白为什么它不想在表中显示我的数据。 我console.log一切,并在控制台中显示结果。 当我转到“网络-预览并响应”时,它将显示包含所有信息的完整json,但我的表为空......
import React,{Component} from 'react';
class ProfilStudent extends Component {
constructor(){
super();
this.state={
isLoading:false,isError:false,students: []
};
}
componentDidmount() {
fetch('http://localhost:8095/dnevnik/student/profil',{
method: 'GET',headers: {
'Authorization': 'Basic ' + window.btoa(this.props.username + ":" + this.props.password),"Content-type": "application/json; charset=UTF-8",'accept': 'application/json',}
})
.then(response => {
return response.json();
})
.then(students => {
this.setState({ students });
});
}
renderStudents() {
return this.state.students.map(student => {
return (
<tr key={student.id}>
<td>{student.id}</td>
<td>{student.firstName}</td>
<td>{student.lastName}</td>
</tr>
);
})
}
render() {
return (
<div>
<table>
<thead>
<tr>
<th>ID</th>
<th>firstName</th>
<th>lastName</th>
<th>username</th>
</tr>
</thead>
<tbody>
{this.renderStudents()}
</tbody>
</table>
</div>
);
}
}
export default ProfilStudent;
我已经尝试了一切。搜索了Internet,stackoverflow上的所有信息,但仍然存在此问题 我在其他班上有相同的代码,并且运行良好。 请问是什么原因,请帮忙!