Omi 生命周期

由 当耐特 创建, 最后一次修改 2017-02-20

生命周期

Lifecycle methodWhen it gets called
componentWillMount / installbefore the component gets mounted to the DOM
componentDidMount / installedafter the component gets mounted to the DOM
componentWillUnmount / uninstall    prior to removal from the DOM                  
componentWillReceivePropsbefore new props get accepted
shouldComponentUpdatebefore render(). Return false to skip render
componentWillUpdate / beforeUpdatebefore render()
componentDidUpdate / afterUpdateafter render()

举个例子

class Timer extends Omi.Component {
    install () {
        this.data = {secondsElapsed: 0};
    }

    tick() {
        this.data.secondsElapsed++;
        this.update();
    }

    installed(){
        this.interval = setInterval(() => this.tick(), 1000);
    }

    uninstall() {
        clearInterval(this.interval);
    }

    render () {
        return <div>Seconds Elapsed:<span> {{secondsElapsed}}</span></div>;
    }
}


以上内容是否对您有帮助:
硅心科技
二维码
建议反馈
二维码