This article shares the specific code of Vue to implement the second kill countdown component for your reference. The specific content is as follows Below is the countdown component for the second kill using Vue Development ideas 1. Request the server to obtain the server time at this moment (based on the server time) Code ImplementationThe following code only shows steps 4 and 5. Component CountDown.vue <template> <div> <input type="datetime-local" :min="currentTime" placeholder="Please enter the start time of the flash sale" v-model="startTime"> <button @click="submit">Start timing</button> </div> <div> <h1>{{ countDownTime }}</h1> </div> </template> <script> let timer = null; let tipTextPrefix = 'Time left until the flash sale starts: '; import moment from "moment"; export default { name: 'CountDown', data() { return { currentTime: moment().format('YYYY-MM-DDTHH:mm'), // Please use the server time calculated in steps 1-3 startTime: moment().format('YYYY-MM-DDTHH:mm'), countDownTime: tipTextPrefix + '0 days 0 hours 0 minutes 0 seconds' }}, methods: { submit: function() { const _this = this; clearInterval(timer); timer = setInterval(() => { _this.countDownTime = _this.countDown(); }, 1000); }, countDown: function() { console.log(this.startTime); const seconds = moment(this.startTime).diff(new Date, 'seconds'); if (seconds <= 0) { clearInterval(timer); return 'Second sale has started'; } const second = seconds%60; const minutes = (seconds-second) / 60; const minute = minutes%60; const hours = (minutes-minute) / 60; const hour = hours%24; const day = (hours-hour) / 24; const res = tipTextPrefix + day + 'day' + hour + 'hour' + minute + 'minute' + second + 'second'; return res; } }, } </script> <style> </style> 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:
|
<<: Solution to the problem of flash back after entering the password in MySQL database
question When we are developing normally, if we w...
Introduction to Linux alarm function Above code: ...
Effect Fading from top to bottom Source code html...
After installing VMware Tools, ① text can be copi...
1. Introduction to fastdfs 1. What is fastdfs Fas...
I worked in operations and maintenance for two ye...
How to achieve internationalization in React? The...
Awk is a powerful tool that can perform some task...
Let's take a look at the command to restart t...
Database Table A: CREATE TABLE task_desc_tab ( id...
Monday to Sunday time format conversion (Y --- ye...
Hello everyone, I am Liang Xu. When using Linux, ...
Preface In Linux kernel programming, you will oft...
First check the /etc/group file: [root@localhost ...
Table of contents 1. Use scripts to encrypt TLS f...