Files
react/B/1/P06.html
T

44 lines
1001 B
HTML
Raw Normal View History

2021-12-27 00:25:34 +08:00
<!--
* @Author: chenxuan
* @Date: 2021-12-26 16:30:03
2021-12-31 00:11:36 +08:00
* @LastEditTime: 2021-12-30 22:12:26
2021-12-27 00:25:34 +08:00
* @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>
2022-01-04 07:43:38 +08:00
<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>
2021-12-27 00:25:34 +08:00
<script type="text/babel">
2021-12-29 00:21:11 +08:00
class Weather extends React.Component{
constructor(props){
super(props)
this.state={
ishot:true
}
}
render(){
const {ishot}=this.state;
2021-12-31 00:11:36 +08:00
// 解决this指向问题
return <h1 onClick={this.demo.bind(this)}>今天天气很{ishot ? '炎热' : '凉爽'}</h1>
}
demo(){
this.setState({
ishot:!this.state.ishot
})
2021-12-29 00:21:11 +08:00
}
}
ReactDOM.render(
<Weather/>,document.getElementById('app')
)
2021-12-31 00:11:36 +08:00
2021-12-27 00:25:34 +08:00
</script>
</body>
</html>