data () {
return {
timeR: null,
timeE: 0,
}
},
methods: {
demo () {
this.timeR = null
this.timeR = setInterval(() => {
this.timeE += 1
}, 1000)
// 以下是要使用定时器的函数
// this.timeTest() ...
},
timeTest () {
if (this.timeR) {
clearInterval(this.timeR)
this.timeE = 0
console.log('超时了');
}
return
// 以下事件就被中断了
// ...
}
}