Omi 生命周期
2018-05-10 11:45 更新
生命周期
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 <div>Seconds Elapsed:<span> {{secondsElapsed}}</span></div>; } }
以上内容是否对您有帮助:
更多建议: