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?
1. Why set maxPostSize? The tomcat container has ...
In this blog, I will walk you through the process...
Preface: Lynis is a security audit and hardening ...
There are many tags in XHTML, but only a few are ...
Quickly modify the table structure of a MySQL tab...
First download JDK. Here we use jdk-8u181-linux-x...
There are three ways to represent colors in HTML, ...
0. Introduction What is the ibdata1 file? ibdata1...
Table of contents 1.1. Enable MySQL binlog 1.2. C...
After installing the latest version 8.0.11 of mys...
Background-image is probably one of those CSS pro...
By default, the reading and writing of container ...
Plot Review In the previous article, we analyzed ...
I have encountered many problems in learning Dock...
The situation is as follows: (PS: The red box repr...