Vue implements real-time refresh of the time display in the upper right corner

Vue implements real-time refresh of the time display in the upper right corner

This article example shares the specific code of Vue to achieve real-time refresh of the time display in the upper right corner for your reference. The specific content is as follows

Rendering

index.js in the utils folder

export default {
  // Get the timestamp in the upper right corner formatDate(time) {
    let newTime = "";
    let date = new Date(time);
    let a = new Array("日","MON","TUE","WED","THUR","FRI","SAT");
    let year = date.getFullYear(),
        month = date.getMonth()+1, //Month starts from 0 day = date.getDate(),
        hour = date.getHours(),
        min = date.getMinutes(),
        sec = date.getSeconds(),
        week = new Date().getDay();
        if(hour<10){
          hour = "0"+hour;
        }
        if(min<10){
          min="0"+min;
        }
        if(sec<10){
          sec = "0"+sec;
        }
    newTime = year + "-"+month+"-" +day +" week"+a[week] + " "+hour+":"+min+":"+sec;
    return newTime;
  }
}

src==>cs.vue in the page folder

<template>
  <div class="main">   
    <!-- Header -->
    <div class="header">     
      <div class="cue_time">{{currentDate}}</div>
    </div>
  </div>
</template>
 
<script>
  import utils from '../utils/index' 
  export default {
    name:"tranin",
    data () {
      return {       
        currentDate: utils.formatDate(new Date()),
        currentDateTimer:null, //header current time}
      
    },
    methods:{
      // Refresh header time refreashCurrentTime(){
        this.currentDate = utils.formatDate(new Date())
      }
 
    },
    mounted(){
      // Timed refresh time this.currentDateTimer = setInterval(this.refreashCurrentTime,1000)
 
    }
  }
</script>

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:
  • Implementation code for getting the current time and refreshing in real time in Vue
  • Vue2.0 countdown plug-in (timestamp refresh jump is not affected)

<<:  MySQL 8.0.23 installation and configuration method graphic tutorial under win10

>>:  Example of ellipsis when CSS multi-line text overflows

Recommend

MySQL master-slave replication principle and points to note

Written in front I have been writing a special to...

SQL implementation of LeetCode (182. Duplicate mailboxes)

[LeetCode] 182.Duplicate Emails Write a SQL query...

JavaScript canvas to achieve raindrop effects

This article example shares the specific code of ...

Docker image import, export, backup and migration operations

Export: docker save -o centos.tar centos:latest #...

Use CSS to achieve circular wave effect

I often see some circular wave graphics on mobile...

Implementation of sharing data between Docker Volume containers

What is volume? Volume means capacity in English,...

Tips for making web table frames

<br />Tips for making web table frames. ----...

Docker builds python Flask+ nginx+uwsgi container

Install Nginx First pull the centos image docker ...

Troubleshooting MySQL high CPU load issues

High CPU load caused by MySQL This afternoon, I d...

Detailed explanation of the process of installing MySQL on Ubuntu 18.04.4

Let's take a look at the process of installin...

Docker container log analysis

View container logs First, use docker run -it --r...

Personal opinion: Talk about design

<br />Choose the most practical one to talk ...

Methods and steps for deploying go projects based on Docker images

Dependence on knowledge Go cross-compilation basi...

React entry-level detailed notes

Table of contents 1. Basic understanding of React...

Implementation of k8s deployment of docker container

Environment: (docker, k8s cluster), continue with...