import React, {Component } from 'react'
export default class Child extends Component {
constructor(props){
// 组件初始化
super(props);
this.state={date:new Date(),flag:true}
}
// 第一次 渲染完毕 适合 setTimeout interval ajax
componentDidMount(){
this.Id = setInterval(()=>{
this.setState({date:new Date()});
},1000)
}
componentDidUpdate(){
console.log("组件更新");
}
// 组件卸载调用
componentWillUnmount(){
clearInterval(this.Id);
}
switchHd(){
this.setState({flag:!this.state.flag});
}
render() {
return (
{this.state.flag?
我喜欢冬天的雪
:我喜欢夏天的风
}
)
}
}