How to implement Vue timer

How to implement Vue timer

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:
  • Implementing a simple timer based on Vue method
  • Vue-cli framework implements timer application
  • Using Vue to implement timer function
  • Vue.js implements simple timer function
  • Vue implements a simple timer component
  • Detailed usage of Vue timer
  • Solve the problem of timer continuing to execute after Vue component is destroyed
  • Vue example code using timer to achieve marquee effect
  • Implementation code of vue timer component
  • How to encapsulate timer components in Vue3

<<:  The process of deploying and running countly-server in docker in win10

>>:  Will mysql's in invalidate the index?

Recommend

Tomcat maxPostSize setting implementation process analysis

1. Why set maxPostSize? The tomcat container has ...

The process of installing Docker in Linux system

In this blog, I will walk you through the process...

Analysis of the use of Linux vulnerability scanning tool lynis

Preface: Lynis is a security audit and hardening ...

Introduction to the usage of common XHTML tags

There are many tags in XHTML, but only a few are ...

How to quickly modify the table structure of MySQL table

Quickly modify the table structure of a MySQL tab...

Linux centOS installation JDK and Tomcat tutorial

First download JDK. Here we use jdk-8u181-linux-x...

MySQL FAQ series: How to avoid a sudden increase in the size of the ibdata1 file

0. Introduction What is the ibdata1 file? ibdata1...

mysql-canal-rabbitmq installation and deployment super detailed tutorial

Table of contents 1.1. Enable MySQL binlog 1.2. C...

6 interesting tips for setting CSS background images

Background-image is probably one of those CSS pro...

Docker Data Storage Volumes Detailed Explanation

By default, the reading and writing of container ...

Listen directive example analysis in nginx

Plot Review In the previous article, we analyzed ...

Implementation of Docker packaging image and configuration modification

I have encountered many problems in learning Dock...

Solution to the horizontal scroll bar in iframe under IE6

The situation is as follows: (PS: The red box repr...