REACT--函数式组件与类式组件

函数式组件与类式组件

//函数式组件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script> <!-- 该文件向外暴露了一个对象 React-Dom --> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script> <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> function Study(){ return ( <ul> <li>学习react</li> <li>学习vue</li> </ul> ) } ReactDOM.render(<Study/>,document.getElementById("app")) </script> </body> </html>
//类式组件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script> <!-- 该文件向外暴露了一个对象 React-Dom --> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script> <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> class Study extends React.Component{ render(){ return( <ul> <li>学习react</li> <li>学习vue</li> </ul> ) } } ReactDOM.render(<Study/>,document.getElementById("app")) </script> </body> </html>

 

上一篇:调试基于 Zephyr 的 IoT 应用程序的最佳实践


下一篇:【Kubernetes】标签与标签选择器