39 lines
944 B
HTML
39 lines
944 B
HTML
<!--
|
|
* @Author: chenxuan
|
|
* @Date: 2021-12-31 00:08:42
|
|
* @LastEditTime: 2022-08-13 16:28:03
|
|
* @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> |