This article example shares the specific code of Vue to implement the timer for your reference. The specific content is as follows What we do here is click the button to start and end the countdown <div class="time" v-if="rptType">{{str}}</div> <div class="receipt" :class="rptType?'jdz':'jiedan'" @click="receipt">Start</div> data(){ return { rptType: false, //Status h: 0, //Define hours, minutes, seconds, milliseconds and initialize them to 0; m:0, ms:0, s:0, time:0, str:'', } }, mounted:function(){ this.$nextTick(function () {//The entire view is rendered}) }, methods:{ getTask: function(e){ this.taskType = e; }, //Start receipt: function() { this.rptType = !this.rptType; if(this.rptType){ this.time=setInterval(this.timer,50); }else{ this.reset() } }, timer: function(){ //define timing function this.ms=this.ms+50; //millisecondsif(this.ms>=1000){ this.ms=0; this.s=this.s+1; //seconds} if(this.s>=60){ this.s=0; this.m=this.m+1; //minutes} if(this.m>=60){ this.m=0; this.h=this.h+1; //hours} this.str =this.toDub(this.h)+":"+this.toDub(this.m)+":"+this.toDub(this.s)+""/*+this.toDubms(this.ms)+"milliseconds"*/; // document.getElementById('mytime').innerHTML=h+"hour"+m+"minute"+s+"second"+ms+"millisecond"; }, toDub: function(n){ //add 0 operation if(n<10){ return "0"+n; } else { return ""+n; } }, reset: function(){ //Reset clearInterval(this.time); this.h=0; this.m=0; this.ms=0; this.s=0; this.str="00:00:00"; }, } 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:
|
<<: The process of deploying and running countly-server in docker in win10
>>: Will mysql's in invalidate the index?
Table of contents Preface 1. Style penetration 1....
The so-called three-column adaptive layout means ...
Table of contents index - General index - Unique ...
I like to pay attention to some news on weekdays a...
We usually have a scanning box when we open the c...
1. Methods for implementing components:組件名稱首字母必須大...
Table of contents 1. Introduction 2. Scenario 3. ...
This article mainly introduces how to implement a...
This example requires downloading and installing ...
1. Modify 1 column update student s, city c set s...
I summarized the previous notes on installing MyS...
Hash Join Hash Join does not require any indexes ...
Preface The database has always been my weak poin...
This article mainly introduces the ::master pseud...
Initialize Dockerfile Assuming our project is nam...