四. React 实现一个 helloWorld

(1)   删除 my-app/public/ 目录下所有文件 只保留  index.html    修改 index.html 代码如下

  

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
       
    <title>React App</title>
  </head>
  <body>
   
    <div id="root"></div>
   
  </body>
</html>

 (2)     进入src 目录  修改index.js  代码如下

  

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

ReactDOM.render(<App />, document.getElementById('root'));

(3)  修改 App.js 代码如下 

import React, { Component } from 'react';
 

function App() {
  return (
    <div >
       hello ,world 
    </div>
  );
}

export default App;

(4)  在 my-app 项目路径下 打开cmd窗口  输入 npm run start    此时 访问  localhost:3000  可以看到 hello World 页面

猜你喜欢

转载自www.cnblogs.com/szw-blog/p/11441335.html