我如何反应(从 Json 获取 axios 并重新排序我的页面)

How can i React ( get axios from Json and ReRandering my page)

为什么我问这个问题(主要return)是搞定的,而

board.writer

不是画图。我如何绘制这个对象

如果我的问题有误,请告诉我。我会修好它

我试过这种方法

  1. 首先使用地图功能
  2. 像这个函数 renderUser = ({board_SEQ, content, writer,subject}) => {
  3. parameter
  4. }
    const Home = () => {
        const initboard = {
            board_SEQ: '',
            writer: '',
            content: '',
            subject: ''
        };
    
        const [boards, setBoard] = useState([]);
    
    
        const load = () => {
            axios.get('http://www.heon.shop:8080/api/boards')
                .then((res) => {
                    const data = res.data;
    
                    setBoard(boards => [...boards, {
                        board_SEQ: (data[0].board_SEQ),
                        writer: data[0].writer,
                        content: data[0].content,
                        subject: data[0].subject
                    }]);
    
    
                })
                .catch((error) => {
                        console.log("error" + error);
                    }
                );
    
        }
        useEffect(() => {
            load();
            console.log("useEffect");
        }, []);
    
        const renderUser = ({board_SEQ, content, writer, subject}) => {
            return (
                <div>
                    <li>he</li>
                    <li>{board_SEQ}</li>
                    <li>{content}</li>
                    <li>{writer}</li>
                    <li>{subject}</li>
                </div>
            );
        }
    
    
        return (
    
            <div>
                {boards.map(board => {
                    <h1> {board.writer}</h1>
                })}
            </div>
        );
    
    }
    export default Home;

也许你可以这样试试,

 <div>
    {boards.map(board => renderUser(board)}
 </div>

如果你想直接使用渲染项目(添加 return 到地图):

 <div>
    {boards.map(board => {
       return <h1> {board.writer}</h1>;
    })}
 </div>