【发布时间】:2019-07-19 09:07:19
【问题描述】:
我有一个需要解析为 React 的对象。 我正在尝试将“行”对象(在节点函数中)转移到反应状态。 下面的 2 段代码在不同的页面上!
另一个问题是 GEThttp://localhost:3000/newnet::ERR_CONNECTION_REFUSED
我目前在本地运行这两个 反应http://localhost:3001/ 节点 - http://localhost:3000/
对此有类似的问题,但我找不到这两个问题的答案! 谢谢
router.get("/new", (req, res) => {
let parentList = sql.fetchAllParents(function(err, rows) {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:3001");
if (err) throw err;
res.render('new', {parents: rows});
});
});
componentDidMount() {
fetch(`http://localhost:3000/new`).then(response => {
console.log(response)
return response.json();
}).then(data => {
// Work with JSON data here
console.log(data,'data');
}).catch(err => {
// Do something for an error here
console.log("Error Reading data " + err);
});
}
【问题讨论】:
-
你可以在包json中使用代理。因此,当我们在 package.json 中添加代理时,每当发生请求时,它都会路由到不同的端口。
-
这里是上面评论中提到的链接:facebook.github.io/create-react-app/docs/…
标签: javascript node.js reactjs