可以用React-Query提取数据
在我的客户端(React JS)上,我想从后端获取数据。但这不起作用。数据的输出不明智。 代码片段,我将Express JS和MongoDB用作数据库。
const url = `http://localhost:5000/items/${id}`;
const { data } = useQuery("data", () => axios(url));
console.log("data", data);
后端的
On my client-side(React js), I want to fetch data from the backend. But it's not working. The output of data is undefiend. Code Snippets
const url = `http://localhost:5000/items/${id}`;
const { data } = useQuery("data", () => axios(url));
console.log("data", data);
In the backend, I am using Express js and MongoDB as databases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试创建用于获取的函数,例如:
然后:
您必须将ID提供给
fetchdata
Try creating a function for fetching, for example:
Then:
You have to provide the id to
fetchData