django - 为什么 React 不显示任何数据?
问题描述
import React, { Component } from 'react';
import axios from 'axios';
我想在页面上显示这个:
class ProjectDeatil extends Component {
constructor(props) {
super(props);
this.state = { user: { name: '' } };
}
.
componentDidMount() {
const { match: { params } } = this.props;
axios.get(`http://localhost:8000/api/project/${params.pk}`)
.then(({ data: user }) => {
console.log( user);
this.setState({"User:": user });
});
}
我添加了她的常量
render() {
const{ user } = this.state;
return (
然后我尝试再次显示它,它仍然没有工作
<div className="col-md-4 text-white animated fadeInUp delay-2s if " >
<h1>{user.title}</h1>
<h1> Hello Dear</h1>
</div>
我也尝试过使用 django rest api,但也没有用。
</div>
);
}
}
export default ProjectDeatil
解决方案
您必须修复此行:
this.setState({"User:": user });
至
this.setState({"user": user });
推荐阅读
- python - Python图像大小不匹配导致IndexError:布尔索引与0维的索引数组不匹配
- php - Wordpress 在另一个页面中包含一个页面
- go - Nocopy 最小的例子?
- java - ResponseEntity和 ResponseEntity 不一样?
- google-apps-script - 短时间内服务调用次数过多:exec qps。- 谷歌表格
- sql-server - 将数据保存到 MS SQL Server 时 MS Access 冻结(有时)
- pluralize - 数量大于1时变复数
- java - 在jsp中查找未关闭的标签
- python - 将 ipython html 对象保存为 pdf
- amazon-polly - 带有 Amazon Polly 的 SSML 标签的情感 TTS