【发布时间】:2021-02-08 03:17:30
【问题描述】:
我正在尝试将数据从 API 传递到我的网站。
我的目录:
项目> server.js |公开的
公共> index.html |样式.css
我的代码,它的一部分,在 server.js 中:
var link, txt; // I want to export these 2 variables to the website
fetch(`url`)
.then(res => res.json())
.then(body => {
console.log(body); //receiving a json body and assigning data to both variables
link = body.path;
txt = body.path;
})
.catch(error => {
console.log(error);
});
我没有找到任何方法来将它操作到 index.html 中,有什么好的建议吗?这可以通过 React 和 Node 实现吗?
在 React 的 App.js 中,我想要这样的东西:
<p>{link} or {text}</p>
我是网络开发新手,如果您能提供任何帮助,我们将不胜感激。
【问题讨论】:
标签: html node.js reactjs express