This article example shares the specific code of Vue to implement the timer function for your reference. The specific content is as follows First we need to know the difference between setTimeout and setInterval setTimeout is only executed once after the specified time. The code is as follows: <script> //Timer runs asynchronously function hello(){ alert("hello"); } //Execute the method using the method name var t1 = window.setTimeout(hello,1000); var t2 = window.setTimeout("hello()",3000);//Use string execution method window.clearTimeout(t1);//Remove the timer</script> setInterval executes in a cycle with a specified time period. The code is as follows: //Real-time refresh time unit is milliseconds setInterval('refreshQuery()',8000); /* Refresh query */ function refreshQuery(){ $("#mainTable").datagrid('reload',null); } In general, setTimeout is used to delay the execution of a method or function. TimerHTML Code <div class="father"> <ul> <li>{{one}}<span>:</span></li> <li>{{two}}<span>:</span></li> <li>{{three}}</li> </ul> <el-button type="primary" @click="startHandler">Start</el-button> <el-button type="primary" @click="endHandler">Pause</el-button> </div> JAVASCRIPT CODE <script> export default { name: 'HelloWorld', data(){ return { flag: null, one : '00', // hour two : '00', // minute three : '00', // second abc : 0, // count of seconds cde : 0, // count of minutes efg : 0, // count of hours } }, props: { msg: String }, mounted() { }, methods:{ // Start timing startHandler(){ this.flag = setInterval(()=>{ if(this.three === 60 || this.three === '60'){ this.three = '00'; this.abc = 0; if(this.two === 60 || this.two === '60'){ this.two = '00'; this.cde = 0; if(this.efg+1 <= 9){ this.efg++; this.one = '0' + this.efg; }else{ this.efg++; this.one = this.efg; } }else{ if(this.cde+1 <= 9){ this.cde++; this.two = '0' + this.cde; }else{ this.cde++; this.two = this.cde; } } }else{ if(this.abc+1 <= 9){ this.abc++; this.three = '0' + this.abc; }else{ this.abc++; this.three=this.abc; } } },100) }, // Pause timing endHandler(){ this.flag = clearInterval(this.flag) } } } </script> The effect is as follows: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Quickly solve the problem of slow startup after Tomcat reconfiguration
>>: How to connect Django 2.2 to MySQL database
KDE Abbreviation for Kool Desktop Environment. A ...
Preface: When we want to clear a table, we often ...
Forms are a major external form for implementing ...
JSON data is displayed and formatted on the HTML ...
Use OSS to upload pictures or attachments in vue ...
HTML structure <body> <div class="w...
Table of contents Preface 1. Demand and Effect ne...
Preface: I heard a long time ago that MySQL 8.0 s...
I installed MySQL smoothly in Ubuntu 16.04 before...
Using provide+inject combination in Vue First you...
Anyone who has used the Linux system should know ...
Canvas is a new tag in HTML5. You can use js to o...
The operating system for the following content is...
Knowing which for loop or iterator is right for o...
This article shares a sharing sidebar implemented...