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