Countdown component for Vue.js.
dist/
├── vue-countdown.js (UMD)
├── vue-countdown.min.js (UMD, compressed)
├── vue-countdown.common.js (CommonJS, default)
└── vue-countdown.esm.js (ES Module)
npm install @xkeshi/vue-countdown vue
In browser:
<script src="/path/to/vue.js"></script>
<script src="/path/to/vue-countdown.js"></script>
import Vue from 'vue';
import VueCountdown from '@xkeshi/vue-countdown';
Vue.component(VueCountdown.name, VueCountdown);
<countdown :time="2 * 24 * 60 * 60 * 1000">
<template slot-scope="props">Time Remaining:{{ props.days }} days, {{ props.hours }} hours, {{ props.minutes }} minutes, {{ props.seconds }} seconds.</template>
</countdown>
<!-- <span>Time Remaining:01 days, 23 hours, 59 minutes, 59 seconds.</span> -->
In browser:
<script>Vue.component(VueCountdown.name, VueCountdown);</script>
- Type:
Boolean
- Default:
true
Start to countdown automatically when initialized.
- Type:
Boolean
- Default:
true
Indicate if emit the countdown events or not.
- Type:
Number
- Default:
1000
Update interval time (in milliseconds) of the countdown.
- Type:
Boolean
- Default:
true
Add a leading zero to the output days, hours, minutes and seconds if they are less than 10.
- Type:
Function
- Default:
() => Date.now()
Generate the current time (in milliseconds) of a specific time zone.
- Type:
Number
- Default:
0
Total number of time (in milliseconds) for the countdown.
Note: The given value should not less than 0
.
- Type:
String
- Default:
'span'
The tag of the component root element in the countdown.
Start to countdown.
<countdown v-bind:auto-start="false" ref="countdown"></countdown>
export default {
mounted() {
this.$refs.countdown.start();
},
};
Pause the countdown.
<countdown ref="countdown"></countdown>
export default {
mounted() {
this.$refs.countdown.pause();
},
};
Stop the countdown.
Require to set the
emit-events
property totrue
, or if you don't need these events, you can set the prop tofalse
for better performance.
This event fires when countdown started.
This event fires when countdown is paused.
This event fires when countdown in progress.
<countdown v-on:countdownprogress="handleCountdownProgress"></countdown>
export default {
methods: {
handleCountdownProgress(data) {
console.log(data.days);
console.log(data.hours);
console.log(data.minutes);
console.log(data.seconds);
console.log(data.totalDays);
console.log(data.totalHours);
console.log(data.totalMinutes);
console.log(data.totalSeconds);
},
},
};
This event fires when countdown stopped.
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Opera (latest)
- Edge (latest)
- Internet Explorer 9+
Maintained under the Semantic Versioning guidelines.