Vue stop countdown problem window.clearInterval ()

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)
    }
  },
Sep.01,2021

  

in. traverses attribute names
to traverse attribute values, you can use
for (let index of Object.values (this.interval2)

Menu