1.基础语法

1.引入三个文件
react.development.js
react-dom.development.js
babel.min.js
这三个地址,将得到的页面全选后复制粘贴到本地的文件中,分别对应react.js、react-dom.js和browser.min.js三个文件

  1. <script src="./js/react.development.js"></script>
  2. <script src="./js/react-dom.development.js"></script>
  3. <script src="./js/babel.min.js"></script>
  1. <div id="test"></div>

2.创建一个虚拟dom对象

  1. // <!-- 创建虚拟dom元素对象 -->
  2. var vDom=<h1>hello react</h1>

3.将虚拟dom渲染到页面真实dom容器中

  1. ReactDOM.render(vDom,document.getElementById("test"))
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div id="test"></div>
  11. <script type="text/javascript" src="./js/react.development.js"></script>
  12. <script type="text/javascript" src='./js/react-dom.development.js'></script>
  13. <script type="text/javascript" src="./js/babel.min.js"></script>
  14. <script type="text/babel">
  15. var vDom = <h1>hello react</h1>
  16. ReactDOM.render(vDom, document.getElementById("test"))
  17. </script>
  18. </body>
  19. </html>