首页 > 其他分享 >React渲染元素DOM

React渲染元素DOM

时间:2023-03-13 10:24:21浏览次数:42  
标签:const render 渲染 DOM element React root

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5     <meta charset="UTF-8">
 6     <meta http-equiv="X-UA-Compatible" content="IE=edge">
 7     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 8     <title>元素渲染</title>
 9     <script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
10     <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
11     <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
12 
13 </head>
14 
15 <body>
16     <div id="root"></div>
17     <script type="text/babel">
18         const root = ReactDOM.createRoot(
19             document.getElementById('root')
20         );
21         // const element= <h1> Hello, world </h1>;
22         // root.render(element);
23         //定时
24         function tick() {
25             const element = (
26               <div>
27                 <h1>Hello, world!</h1>
28                 <h2>It is {new Date().toLocaleTimeString()}</h2>
29               </div>
30             );
31             root.render(element);
32           }
33           
34           setInterval(tick, 1000);
35     </script>
36 </body>
37 
38 </html>

 

标签:const,render,渲染,DOM,element,React,root
From: https://www.cnblogs.com/mo3408/p/17210419.html

相关文章