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

Some tips for using less in Vue projects

Table of contents Preface 1. Style penetration 1....

Mysql index types and basic usage examples

Table of contents index - General index - Unique ...

Example code for implementing a QR code scanning box with CSS

We usually have a scanning box when we open the c...

React State state and life cycle implementation method

1. Methods for implementing components:組件名稱首字母必須大...

nuxt.js multiple environment variable configuration

Table of contents 1. Introduction 2. Scenario 3. ...

Vue implements websocket customer service chat function

This article mainly introduces how to implement a...

Detailed steps for installing and debugging MySQL database on CentOS7 [Example]

This example requires downloading and installing ...

How to use a field in one table to update a field in another table in MySQL

1. Modify 1 column update student s, city c set s...

MySQL 5.7.17 winx64 installation and configuration graphic tutorial

I summarized the previous notes on installing MyS...

Mysql 8.0.18 hash join test (recommended)

Hash Join Hash Join does not require any indexes ...

Learn MySQL in a simple way

Preface The database has always been my weak poin...

Use of marker tags in CSS list model

This article mainly introduces the ::master pseud...

How to deploy nodejs service using Dockerfile

Initialize Dockerfile Assuming our project is nam...