Omi 生命周期
生命周期
Lifecycle method |
When it gets called |
componentWillMount / install |
before the component gets mounted to the DOM |
componentDidMount / installed |
after the component gets mounted to the DOM |
componentWillUnmount / uninstall |
prior to removal from the DOM |
componentWillReceiveProps |
before new props get accepted |
shouldComponentUpdate |
before render() . Return false to skip render |
componentWillUpdate / beforeUpdate |
before render()
|
componentDidUpdate / afterUpdate |
after 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 Seconds Elapsed: {{secondsElapsed}}
;
}
}