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:
|
<<: MySQL 8.0.23 installation and configuration method graphic tutorial under win10
>>: Example of ellipsis when CSS multi-line text overflows
Written in front I have been writing a special to...
[LeetCode] 182.Duplicate Emails Write a SQL query...
This article example shares the specific code of ...
Export: docker save -o centos.tar centos:latest #...
I often see some circular wave graphics on mobile...
What is volume? Volume means capacity in English,...
<br />Tips for making web table frames. ----...
Install Nginx First pull the centos image docker ...
High CPU load caused by MySQL This afternoon, I d...
Let's take a look at the process of installin...
View container logs First, use docker run -it --r...
<br />Choose the most practical one to talk ...
Dependence on knowledge Go cross-compilation basi...
Table of contents 1. Basic understanding of React...
Environment: (docker, k8s cluster), continue with...