首页 > 解决方案 > 为什么 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

标签: djangoreactjs

解决方案


您必须修复此行:

this.setState({"User:": user });

this.setState({"user": user });

推荐阅读