class Background extends React.Component{ constructor(opts) { super(opts); this.initStatus(); } initStatus() { this.state = { effect: false } } render(){ this.initStatus(); return <div className={cs({background: true, effect: this.state.effect})}> <div className="background-pannel"> <div className="background-image-back"></div> </div> <div className="background-pannel"> <div className="background-image"></div> </div> </div> } componentDidMount() { this.setState({effect: true}, ()=>{ console.log(this.state.effect); }) } }export { Background }
为什么没有效果,打印出来的effect
值依然是false
?
红糖糍粑
相关分类