页面上多个定时器怎么清除
发布于 5 年前 作者 jiexue 9762 次浏览 来自 问答

列表中有多个定时器怎么在退出页面时候清除多个定时器

3 回复

在 onHide 和 onUnload 里边清除

onload里面

this. tickers = []

然后每创建一个timer就push进去一个

this.tickers.push(setInterval(func, 1000)

onUnload里面

this.tickers.forearch(t => {

    if(t){

        clearInterval(t)

    }

})    

onUnload:function(){

    //TODO:clearTimeout

}

回到顶部