如何显示文章详细信息,我面临问题

时间:2019-07-14 17:30:18

标签: reactjs api

我正在尝试显示文章的详细信息,但是我遇到了一个问题。当我单击该文章以查看其详细信息时,它什么也没有显示,因此请帮助我解决该问题

import React, { Component } from 'react'
import axios from 'axios';


class Details extends Component {
    constructor(props){
      super(props);

    this.state = {
        question: null,
      };
}

async componentDidMount() {
    const { match: { params } } = this.props;
    const question = (await axios.get(`http://trivago-magazine-work-sample-server.s3-website.eu-central-1.amazonaws.com/latest_posts.json/${params.id}`)).data;
    console.log(question)
    this.setState({
        question
    });
  }


//   }

render() {
    const {question} = this.state;

    if (question === null) return <p>Loading ...</p>;
    return (
        <div>
           <h1> Hello </h1> {question.title}
        </div>
    )
  }
}

 export default Details  

enter image description here

0 个答案:

没有答案