代碼如下,跳轉(zhuǎn)頁(yè)面后定時(shí)器依然在執(zhí)行created(){ this.interval()
},
beforeDestroy () { console.log('清除定時(shí)器')
clearInterval(this.interval)
},
methods: {
interval(){
setInterval(()=>{ console.log('執(zhí)行定時(shí)器') this.loadList()
},3000)
},
}
1 回答

慕標(biāo)5832272
TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
清除的是定時(shí)器的引用,而不是方法
created(){ this.interval() }, beforeDestroy () { console.log('清除定時(shí)器') clearInterval(this._inter) }, methods: { interval(){ this._inter = setInterval(()=>{ console.log('執(zhí)行定時(shí)器') this.loadList() },3000) }, }
添加回答
舉報(bào)
0/150
提交
取消