理想是火,点燃熄灭的灯。
<!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"></script> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> <script src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script> </head> <body> <div id="root"></div> </body> <script type="text/babel"> class App extends React.Component { constructor(props) { super(props); this.state = { testVal: "123", }; } render() { console.log(this); return <h1> {this.state.testVal} !</h1>; } } ReactDOM.render(<App />, document.getElementById("root")); </script> </html>
script
标签里面写react代码了,但是这里有个重点,那就是script标签的类型type
,正常的script标签类型是type="text/javascript"
,而一般写模板语法时,写的类型是type="text/html"
,但是react的script标签的类型是type="text/babel"
**记住一定要写成这个类型,否则会报错,解读不了react代码作者: Bill 本文地址: http://biaoblog.cn/info?id=1607050860000
版权声明: 本文为原创文章,版权归 biaoblog 个人博客 所有,欢迎分享本文,转载请保留出处,谢谢!