当前位置: 首页 > Web前端 > vue.js

vue如何清除定时器

时间:2023-03-31 18:40:57 vue.js

1.定义全局变量data(){return{textClose:""m:'',//格式化后分钟s:'',/格式化后秒数};},2.调用前清除定时器letexamMinute=90;//90FENZHOGNlettolTimers=examMinute*60*1000;让tolS=tolTimers;constmm=Math.floor(tolTimers/1000/60);constss=Math.floor((tolTimers/1000)%60);那.m=mm>9?毫米:'0'+毫米;那.s=ss>9?ss:'0'+ss;//清除定时器that.textClose&&clearInterval(that.textClose);that.textClose=null;that.textClose=window.setInterval(()=>{if(tolS<=1000){//倒计时that.automaticSubmit=true;window.clearInterval(that.textClose);}else{tolS-=1000;//控制台.log('tolS',tolS);if(tolS<=5*60*1000){that.countDownFlag=true;}constmm=parseInt((tolS/1000/60))constss=parseInt(tolS/1000%60)那.m=mm>9?毫米:'0'+毫米;那.s=ss>9?ss:'0'+ss;}},1000);//营销定时器that.$once('hook:beforeDestroy',()=>{clearInterval(that.textClose);})