在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/數(shù)據(jù)庫  HTML/ vue中,在methods里的一個function里有個定時器,在另一個func

vue中,在methods里的一個function里有個定時器,在另一個function里如何清除它

在組件里,在一個function里設(shè)全局的timer=Interval(),在另一方法里找不到。如何跨function清除

回答
編輯回答
萢萢糖

data里寫個變量timer, 定義定時器的時候 this.timer = setInterval()
在其他function里, 用clearInterval(this.timer)清除即可

2017年4月2日 21:02
編輯回答
老梗

在data里聲明一個timer
data() {
return {

timer: undefined

}
},
methods: {
a() {
this.timer = setInterval(()=>{},1000)
},
b() {
clearInterval(this.timer)
}

2018年5月31日 18:23
編輯回答
萌二代

把定時器綁定在this下面

2017年5月26日 22:00