Krishya | e71688a | 2025-04-10 21:25:17 +0800 | [diff] [blame^] | 1 | import React, { useState, useEffect } from'react'; |
| 2 | import axios from 'axios'; |
| 3 | |
| 4 | const PostDetail = ({ post_id }) => { |
| 5 | const [post, setPost] = useState({}); |
| 6 | |
| 7 | useEffect(() => { |
| 8 | const fetchPost = async () => { |
| 9 | try { |
| 10 | const response = await axios.get(`/echo/forum/posts/${post_id}`); |
| 11 | setPost(response.data); |
| 12 | } catch (error) { |
| 13 | console.error('Error fetching post detail:', error); |
| 14 | } |
| 15 | }; |
| 16 | fetchPost(); |
| 17 | }, [post_id]); |
| 18 | |
| 19 | return ( |
| 20 | <div> |
| 21 | <h1>{post.title}</h1> |
| 22 | <p>作者: {post.author}</p> |
| 23 | <p>内容: {post.Postcontent}</p> |
| 24 | {post.imgUrl && <img src={post.imgUrl} alt={post.title} />} |
| 25 | </div> |
| 26 | ); |
| 27 | }; |
| 28 | |
| 29 | export default PostDetail; |