I\xe2\x80\x99m 使用 React JS。我有登录页面,它从端点接收数据作为响应。I\xe2\x80\x99m 在窗口中存储来自响应的不同组件。变量,因为它们必须在不同的组件中访问。这仅在加载新组件时才起作用,在它\xe2\x80\x99s刷新窗口之后。变量变为空。
\n\n这是我的登录组件:
\n\nhandleSubmit(event) {\nevent.preventDefault()\n\naxios\n .post("EDN POINT LINK",\n {\n email: this.state.email,\n password: this.state.password\n\n })\n .then((response) => {\n\n console.log(response);\n\n // STORING ID\n window.id = window.responseDetails.map(\n mID => mID.id\n )\n console.log(\'ID is: \' + window.id);\n\n // STORING TOKEN\n window.token = window.responseDetails.map(\n mToken => mToken.token\n )\n console.log(\'TOKEN is: \' + window.token);\n\n // STORING ERROR\n window.error = window.responseDetails.map(\n mError => mError.error\n )\n console.log(\'ERROR is: \' + window.error);\nRun Code Online (Sandbox Code Playgroud)\n\n这是我访问窗口的组件。多变的:
\n\n render() {\n\n console.log(window.id)\n return (\n\n )\n}\nRun Code Online (Sandbox Code Playgroud)\n\n如果我有更多时间,我会实现 Redux …