页面上多个定时器怎么清除

发布于 7 年前作者 jiexue9922 次浏览最后编辑 7 年前来自 ask

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

3 回复
gcheng
gcheng1 楼6 年前

在 onHide 和 onUnload 里边清除

qliu
qliu2 楼6 年前

onload里面

this. tickers = []

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

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

onUnload里面

this.tickers.forearch(t => {

    if(t){

        clearInterval(t)

    }

})    

wei61
wei613 楼5 年前

onUnload:function(){

    //TODO:clearTimeout

}