| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <!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="./babel.min.js"></script>
- <script src="./react.development.js"></script>
- <script src="./react-dom.development.js"></script>
- </head>
- <body>
- <div id="root"></div>
- <script type="text/babel">
- let root = ReactDOM.createRoot(document.getElementById("root"));
- function App() {
- return (
- <Main />
- )
- }
- class Main extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- hi: '哈哈哈哈哈',
- aa: '小明'
- }
- console.log(this)
- this.handleHi = this.handleHi.bind(this);
- }
- handleHi() {
- console.log('hi', this)
- this.setState({
- hi: '哈哈'
- })
- }
- // handleHi=() =>{
- // console.log('hi',this)
- // this.setState({
- // hi:'哈哈'
- // })
- // }
- render() {
- console.log(this, 'this')
- return (
- <div>
- <h1>你好</h1>
- <h3 onClick={this.handleHi}>{this.state.hi}</h3>
- {/*<h3 onClick={this.handleHi.bind(this)}>{this.state.hi}</h3>*/}
- <h3 onClick={()=>{
- this.setState({
- aa:'12'
- })
- }}>{this.state.aa}</h3>
- </div>
- )
- }
- }
- root.render(<App />);
- </script>
- </body>
- </html>
|