更改代码后,输出的代码不会更改

时间:2018-11-28 13:24:12

标签: html reactjs

我开始通过编写简单的代码来学习反应。但它显示的是浏览器中不同的输出,我的意思是上一个示例。我刷新了很多次,但注意已更改。我用Visual Studio代码编写代码。 我将这段代码写为App.js

 import React from 'react';

 class App extends React.Component {
 constructor(props) {
  super(props);

  this.state = {
     header: "Header from state...",
     content: "Content from state..."
  }
}
render() {
   return (
      <div>
         <h1>{this.state.header}</h1>
        <h2>{this.state.content}</h2>
     </div>
   );
}
}
export default App;

这是main.js

 import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';

ReactDOM.render(<App />, document.getElementById('app'));
This will produce the following result.

此为index.html

<!DOCTYPE html>
<html lang = "en">
   <head>
      <link rel="shortcut icon" href="">

      <meta charset = "UTF-8">
      <title>React App</title>
   </head>
   <body>
      <div id = "app">

      </div>
      <script src="build/bundle.js"></script>
    </body>
</html>

0 个答案:

没有答案