javascript - React中setState方法无效
怪我咯
怪我咯 2017-04-11 11:15:02
0
4
413

看代码

class Background extends React.Component{
    constructor(opts) {
        super(opts);
        this.initStatus();
    }
    initStatus() {
        this.state = {
            effect: false
        }
    }
    render(){
        this.initStatus();

        return <p className={cs({background: true, effect: this.state.effect})}>
            <p className="background-pannel">
                <p className="background-image-back"></p>
            </p>
            <p className="background-pannel">
                <p className="background-image"></p>
            </p>
        </p>
    }
    
    componentDidMount() {

        this.setState({effect: true}, ()=>{
            console.log(this.state.effect);
        })
    }
}

export { Background }

为什么没有效果,打印出来的effect值依然是false

怪我咯
怪我咯

走同样的路,发现不同的人生

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!