当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
R中设置图形参数--函数par()详解
训练集Loss收敛,但是测试集Loss震荡的厉害?
R简单统计计算--笔记
impdp import data
Minio分布式存储系统
opencv
先人一步,不再错过,链读APP即将上线!
2021-07-09
链读|最新最全的数字藏品发售日历-08.02
idm下载器如何使用 idm下载器使用技巧
私有化搭建个人网盘 NextCloud
tinymce富文本编辑器
转载fstream,ifstream的详细用法
多表查询 笔记
视图【】【】【】【】
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
Using sqlplus to operate database in shell script
Count down the six weapons of the domestic interface collaboration platform!
MySql constraints
使用Tenserboard可视化深度学习训练过程