this is the countdown function I do. The original intention is to use the destroyed function to stop the countdown when leaving the page, but I can"t do it in many ways. Please take a look at
.//
setIntervalForTime2(Pinyin, Id) {
clearInterval(this.interval2[Pinyin]);
this.interval2[Pinyin] = window.setInterval(() => {
//
var h = Math.floor(this.openTime[Pinyin] / 3600)
var m = Math.floor((this.openTime[Pinyin] / 60 % 60))
var s = Math.floor((this.openTime[Pinyin] % 60))
let hour = h < 10 ? "0" + h : h
let min = m < 10 ? "0" + m : m
let sec = s < 10 ? "0" + s : s
let time = ""
time = hour + ":" + min + ":" + sec
this.endOpenTime1[Pinyin] = time
if (this.openTime[Pinyin] <= 0) {
this.getOpenTime2(Pinyin, Id)
}
this.openTime[Pinyin]--
}, 1000);
},
The destroyed function is written by me on the Internet, but it doesn"t seem to work. After leaving this page, I will keep asking for this function this.getOpenTime2 (Pinyin, Id)
. destroyed() {
for (let index in this.interval2) {
window.clearInterval(index)
}
},