blob: f7067bf2e86e1bf2f6ac4981edb08c331cfa7385 [file] [log] [blame]
Krishyae71688a2025-04-10 21:25:17 +08001import React, { useState, useEffect } from'react';
2import axios from 'axios';
3
4const 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
29export default PostDetail;