在狀態初始化時設定一個state{timer:null}
在componentDidMount方法中設置定時執行的方法
this.state.timer=setInterval(()=>{ //需要定時執行的方法 }, 5000)
在componentWillUnmount方法中要對定時器進行銷毀
if(this.state.timer!= null) { clearInterval(this.state.timer); }
在狀態初始化時設定一個state{timer:null}
在componentDidMount方法中設置定時執行的方法
this.state.timer=setInterval(()=>{ //需要定時執行的方法 }, 5000)
在componentWillUnmount方法中要對定時器進行銷毀
if(this.state.timer!= null) { clearInterval(this.state.timer); }
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。