【发布时间】:2020-06-11 03:36:21
【问题描述】:
是否可以将变量值从反应构造函数发布到 nodejs 后端。我们希望在页面加载到 nodejs 时发布某些数据并在后端执行一些功能。
constructor(props) {
super(props);
const tokenFetch = localStorage.getItem("JWT");
const nameFetch = localStorage.getItem("Name");
this.state = {
userLoggedIn,
name: nameFetch,
tokenFetch: tokenFetch
};
}
在构造函数中,我们希望将名称和 tokenFetch 发布到后端。
【问题讨论】:
-
除非您向我们展示一些您迄今为止尝试过的代码,否则我们无法为您提供帮助。
-
问题是一般我们从表单中发布数据,而这里我们要从构造函数中发布数据。因此,目前没有为该问题编写代码。更新:检查 OP 的代码
-
尝试向后端发出请求(get、post ...)
-
@YashKumarVerma 是对的,但不要使用
request,在前端应用程序中使用axios,在后端调用中最好使用request。 -
但是我在哪里发出帖子请求,这就是这里的问题。因为不涉及任何形式。
标签: node.js reactjs express react-router router