The setInterval timer is used in the vue method, which is still executed after leaving the page. I would like to ask how to solve the problem.

this is the timer used in the methods method

 async verScheme(index,row){
        var uuid =  this.getUuid();
        try {
          let ret = await this.$Api.OperationAccess.SystemAccess.Verification({
            id: row.id,
            uuid : uuid,
          })
           this.dialogFormVisible1 = true;
            this.interval =setInterval(()=> {
              this.log(uuid);
            },1000);
        }catch ( ret ){
          this.$message.error( ret.msg ? ret.msg : " : " + ret )
        }
      }

this is using beforeDestory ()

created(){
      this.Init();
      this.timer = this.interval;
    },

    beforeDestroy() {
      if (this.timer) { // 
        clearInterval(this.timer); //
      }
    },



did your this.interval return the correct timer


you can try requireanimationframe


the reference to your timer is not saved correctly


an opinion on your way of writing
  • since your timer has been stored with a interval , why save it to timer in the created cycle
  • you execute the init function during the created cycle. Can you make sure that this function is finished before you execute the following interval assignment to timer ? If there is no guarantee, then you should know what this timer holds
  • .
your way of writing is rather troublesome. It is recommended that you do not have to save it in an instance, save memory, and you do not even have to write code in the beforDestory cycle
.
//
let timer = setInterval(() => {
    //
} 1000)
//thisvue
this.$once('hook:beforeDestory', function() {
    clearInterval(timer)
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eac48e-47e8a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eac48e-47e8a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?