当前位置:网站首页>Timer (setInterval) on and off
Timer (setInterval) on and off
2022-08-10 05:48:00 【Why can't I get enough to eat?】
The timer I set is turned on when I click to display the subcomponent. After waiting for 30s, I will close the subcomponent without clicking the page. Every time I click on the page, it will be closed without clicking within 30s. When I click to exit the subcomponent page, it will also be closed.will close the timer
// Start the timer when the parent component displays the child componentthis.$refs.manMachine.openOrCloseTime(true)Define the name of the timer and the variable used to count in the subcomponent

// start the timeropenOrCloseTime(isOpen){// When the parent component calls the method, the parameter is passed to decide whether to start the timerif(isOpen==true){timer=setInterval(()=>{this.count--// Turn off the timer when the count variable value becomes 0if(this.count==0){this.close(timer);}},1000)}else{this.close(timer);}},// close the timerclose(timer){clearInterval(timer);// restore the count variable to the initial value for the next usethis.count=30;// Modify the variable value passed from the parent component to control whether the child component is displayed to close the child componentthis.$emit("update:isChat", this.show);},Remember to call the method to close the timer when closing the page
After operating on the page, restore the initial value of the count variable this.count=30, and let the timer re-time
边栏推荐
猜你喜欢

Chain Reading Good Article: Jeff Garzik Launches Web3 Production Company

先人一步,不再错过,链读APP即将上线!

Database Notes Create Database, Table Backup

多表查询 笔记

pytorch框架学习(6)训练一个简单的自己的CNN (三)细节篇

链读|最新最全的数字藏品发售日历-07.29

反射【笔记】

链读|最新最全的数字藏品发售日历-08.02

Chain Reading|The latest and most complete digital collection sales calendar-07.29

视图【】【】【】【】
随机推荐
error in ./node_modules/cesium/Source/ThirdParty/zip.js
OSPF实验
链读|最新最全的数字藏品发售日历-08.02
链读推荐:从瓷砖到生成式 NFT
第六次实验
YOLOv5 PyQt5(一起制作YOLOv5的GUI界面)
ResNet的基础:残差块的原理
Count down the six weapons of the domestic interface collaboration platform!
Small program wx.request simple Promise package
Database Notes Create Database, Table Backup
视图【】【】【】【】
先人一步,不再错过,链读APP即将上线!
第十天作业
Analysis of the investment value of domestic digital collections
小程序wx.request简单Promise封装
集合 set接口
Batch add watermark to pictures batch scale pictures to specified size
kaggle小白必看:小白常见的2个错误解决方案
你不知道的常规流
【写下自用】每次都忘记如何train?记录如何训练自己的yolov5