class Weather extends React.Component{
//构造器调用几次? ———— 1次
constructor(props){
console.log('constructor');
super(props)
//初始化状态
this.state = {
isCold:false
}
this.changeWeather = this.changeWeather.bind(this)
}
render(){
const {isCold} = this.state
return <h1 onClick={this.changeWeather}>今天气候很{isCold ? '舒服' : '不舒服'}</h1>
}
changeWeather(){
const isCold = this.state.isCold
this.setState({isCold:!isCold})
console.log(this);
}
}