簡體   English   中英

Reactjs Expressjs - 為什么我的 React.js 代碼不使用來自我的 Express 服務器的更新代碼,而是使用舊代碼,即使在我刷新網頁后也是如此?

[英]Reactjs Expressjs - Why isn't my React.js code using updated code from my Express server, but instead old code, even after I refresh the webpage?

我正在開發一個 React.js-Express.js 網站,我已經借助在線示例設置了一些基本代碼。 我讓 Express.js 將一個數組發送到前端以在解析后顯示它。 但是,當我稍微更改數組時——字面上將一個字符串更改為另一個字符串——我的前端沒有更新。

Express - users.js 文件

 var express = require('express'); var router = express.Router(); /* GET users listing. */ router.get('/', function(req, res, next) { //res.send('respond with a resource'); res.json([{ id: 1, username: "bye" //I changed this string (used to be "samsepi0l") }, { id: 2, username: "hi" //And this string (used to be "D0loresH4ze") }]); }); module.exports = router;

React - About.js 文件

 import React from 'react' // import { Link } from 'react-router-dom' import { Header } from './Header' export class About extends React.Component { state = {users: []} componentDidMount() { fetch('/users').then(res => res.json()).then(users => this.setState({ users })); } render() { return ( <div> <Header /> <h2 id="other_pages_h2">About</h2> <div> <h1>Users</h1> {this.state.users.map(user => <div key={user.id} style={{color: 'white'}}>{user.username}</div> )} </div> </div> ) } }

由於某種原因, /about頁面仍然顯示“samsepi0l”和“D0loresH4ze”。 我怎樣才能解決這個問題?

這可能是由臭名昭著的緩存引起的。 通常只需按 Crtl + F5 即可解決此問題,如果不起作用,請清除瀏覽器歷史記錄。

如果您仍然遇到同樣的問題,那么您在代碼更改后沒有保存文件和/或重新啟動服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM