This article example shares the specific code of Vue to realize the time countdown function for your reference. The specific content is as follows need:Make a countdown effect for the remaining payment time Effect picture:Code:<template> <div>Remaining payment time: {{count}}</div> </template> <script> export default { data() { return { count: '', // countdown seconds: 864000 // 10 days of seconds} }, mounted() { this.Time() //Call the timer}, methods: { // Day, hour, minute, and second formatting function countDown() { let d = parseInt(this.seconds / (24 * 60 * 60)) d = d < 10 ? "0" + d : d let h = parseInt(this.seconds / (60 * 60) % 24); h = h < 10 ? "0" + h : h let m = parseInt(this.seconds / 60 % 60); m = m < 10 ? "0" + m : m let s = parseInt(this.seconds % 60); s = s < 10 ? "0" + s : s this.count = d + 'day' + h + 'hour' + m + 'minute' + s + 'second' }, //The timer parameter is reduced by 1 every 1 second Time() { setInterval(() => { this.seconds -= 1 this.countDown() }, 1000) }, } } </script> The seconds of the time can be modified according to your needs Let me share with you another piece of code: vue hour, minute, second countdown countTime: function () { //Get the current time var date = new Date(); var now = date.getTime(); //Set the deadline var endDate = new Date("2018-10-22 23:23:23"); var end = endDate.getTime(); //Time difference var leftTime = end - now; //Define variables d, h, m, s to save countdown time if (leftTime >= 0) { d = Math.floor(leftTime / 1000 / 60 / 60 / 24); this.h = Math.floor(leftTime / 1000 / 60 / 60 % 24); this.m = Math.floor(leftTime / 1000 / 60 % 60); this.s = Math.floor(leftTime / 1000 % 60); } console.log(this.s); //Recursively call the countTime method every second to display the dynamic time effect setTimeout(this.countTime, 1000); } For more articles about countdown, please see the special topic: "Countdown Function" 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:
|
<<: Analysis of the method of setting up scheduled tasks in mysql
>>: How to Delete Junk Files in Linux Elegantly
Data URI Data URI is a scheme defined by RFC 2397...
mysql-5.7.20-winx64.zipInstallation package witho...
1. Download MySQL Community Server 5.7.16 and ins...
What is Redis Cluster Redis cluster is a distribu...
If you want to understand React Router, you shoul...
How to implement the "Set as homepage" ...
Everyone knows that images on web pages are genera...
1. Current date select DATE_SUB(curdate(),INTERVA...
In web front-end development, it is inevitable to ...
I have a product parts table like this: part part...
Problem Description Recently, when I was building...
Previously, we knew several attributes of backgro...
Table of contents need: Function Points Rendering...
Table of contents Overview 1. Acquisition and pro...
MySQL paging analysis principle and efficiency im...