【发布时间】:2022-01-08 15:54:15
【问题描述】:
我正在尝试创建一个简单的 CRUD MERN 应用程序,在此应用程序中,数据显示在我的控制台中,但我想在我的 UI 部分中显示它。请告诉我如何在我们的前端显示控制台部分。
AllUser.js
这是 Alluser.js 文件,我想在其中显示来自后端的控制台数据
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { getUsers } from "./api";
const UserData = () => {
const [users, setUser] = useState([]);
useEffect(() => {
AllUsers();
}, []);
const AllUsers = async () => {
const response = await getUsers();
console.log(response.data);
setUser(response.data);
};
return (
<div>
<div className="container">
<table className="table table-hover table-bordered mt-3">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
{users.map((index,user) => {
<tr key={index}>
<th scope="row">{user.id}</th>
<td>{user.email}</td>
<td>{user.name}</td>
<td>{user.phone}</td>
</tr>;
})}
</tbody>
</table>
</div>
</div>
);
};
export default UserData;
【问题讨论】:
标签: node.js reactjs mongodb express