xx
This commit is contained in:
+9
-5
@@ -1,7 +1,7 @@
|
||||
<!--
|
||||
* @Author: chenxuan
|
||||
* @Date: 2021-12-26 16:30:03
|
||||
* @LastEditTime: 2021-12-29 00:19:18
|
||||
* @LastEditTime: 2021-12-30 22:12:26
|
||||
* @LastEditors: chenxuan
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
@@ -26,15 +26,19 @@
|
||||
}
|
||||
render(){
|
||||
const {ishot}=this.state;
|
||||
return <h1 onClick={demo}>今天天气很{ishot ? '炎热' : '凉爽'}</h1>
|
||||
// 解决this指向问题
|
||||
return <h1 onClick={this.demo.bind(this)}>今天天气很{ishot ? '炎热' : '凉爽'}</h1>
|
||||
}
|
||||
demo(){
|
||||
this.setState({
|
||||
ishot:!this.state.ishot
|
||||
})
|
||||
}
|
||||
}
|
||||
ReactDOM.render(
|
||||
<Weather/>,document.getElementById('app')
|
||||
)
|
||||
function demo(){
|
||||
console.log('xxx')
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<!--
|
||||
* @Author: chenxuan
|
||||
* @Date: 2021-12-31 00:08:42
|
||||
* @LastEditTime: 2021-12-31 00:11:18
|
||||
* @LastEditors: chenxuan
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>state</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="./package/old/react.development.js"></script>
|
||||
<script src="./package/old/react-dom.development.js"></script>
|
||||
<script src="./package/old/babel.min.js"></script>
|
||||
<script type="text/babel">
|
||||
class Weather extends React.Component{
|
||||
state={ishot:true}
|
||||
render(){
|
||||
const {ishot}=this.state;
|
||||
return <h1 onClick={this.demo}>今天天气很{ishot ? '炎热' : '凉爽'}</h1>
|
||||
}
|
||||
demo=()=>{
|
||||
this.setState({
|
||||
ishot:!this.state.ishot
|
||||
})
|
||||
}
|
||||
}
|
||||
ReactDOM.render(
|
||||
<Weather/>,document.getElementById('app')
|
||||
)
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user