| // src/pages/Forum/CreatePost.jsx |
| import React, { useState } from 'react'; |
| import axios from 'axios'; |
| const CreatePost = ({ userId }) => { |
| const [title, setTitle] = useState(''); |
| const [content, setContent] = useState(''); |
| const [imageUrl, setImageUrl] = useState(''); |
| const handleSubmit = async (e) => { |
| postData.imgerrul = imageUrl; |
| const response = await axios.post( |
| `/echo/forum/posts/${userId}/creatPost`, |
| if (response.status === 201) { |
| console.error('帖子创建失败:', error); |
| <div className="create-post"> |
| <form onSubmit={handleSubmit}> |
| onChange={(e) => setTitle(e.target.value)} |
| onChange={(e) => setContent(e.target.value)} |
| <label>图片 URL(可选):</label> |
| onChange={(e) => setImageUrl(e.target.value)} |
| <button type="submit">发布</button> |
| export default CreatePost; |