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

Implementation of waterfall layout + dynamic rendering

Table of contents Typical waterfall website Water...

Faint: "Use web2.0 to create standard-compliant pages"

Today someone talked to me about a website develo...

Super detailed basic JavaScript syntax rules

Table of contents 01 JavaScript (abbreviated as: ...

Getting Started with Mysql--sql execution process

Table of contents 1. Process 2. Core Architecture...

Example code of CSS layout at both ends (using parent's negative margin)

Recently, during the development process, I encou...

How to display TIF format images in browser

The browser displays TIF format images Copy code T...

HTML (css style specification) must read

CSS style specifications 1. Class Selector 2. Tag...

Example of Html shielding right-click menu and left-click typing function

Disable right-click menu <body oncontextmenu=s...

Detailed explanation of MySql data type tutorial examples

Table of contents 1. Brief Overview 2. Detailed e...

VMware Workstation Installation (Linux Kernel) Kylin Graphic Tutorial

This article shares with you how to install Kylin...

Detailed steps to configure MySQL remote connection under Alibaba Cloud

Preface As we all know, by default, the MySQL ins...