Vue 2 countdown and timer component
npm install vuejs-countdown-timer``bash`
npm i vuejs-countdown-timer -S
| Supported Package | Version |
| ----------------- | ------- |
| Vue | 2.5+ |
Import component
`es6`
// global register at main.js
import VueCountdownTimer from 'vuejs-countdown-timer';
Vue.use(VueCountdownTimer);
Vue default template
`vue
@end_callback="endCallBack('event ended')"
:start-time="'2018-10-10 00:00:00'"
:end-time="1481450115"
:interval="1000"
:start-label="'Until start:'"
:end-label="'Until end:'"
label-position="begin"
:end-text="'Event ended!'"
:day-txt="'days'"
:hour-txt="'hours'"
:minutes-txt="'minutes'"
:seconds-txt="'seconds'">
`
Vue Customized template
`vue
@end_callback="endCallBack('event ended')"
:start-time="'2018-10-10 00:00:00'"
:end-time="1481450115"
:interval="1000"
:start-label="'Until start:'"
:end-label="'Until end:'"
label-position="begin"
:end-text="'Event ended!'"
:day-txt="'days'"
:hour-txt="'hours'"
:minutes-txt="'minutes'"
:seconds-txt="'seconds'">
{{scope.props.startLabel}}:
{{scope.props.endLabel}}:
{{scope.props.days}}{{scope.props.dayTxt}}
{{scope.props.hours}}{{scope.props.hourTxt}}
{{scope.props.minutes}}{{scope.props.minutesTxt}}
{{scope.props.seconds}}{{scope.props.secondsTxt}}
{{scope.props.startLabel}}:
{{scope.props.endLabel}}:
{{ scope.props.endText}}
`
| Slot name | Description |
| ----------- | --------------------- |
| start-label | Timer start label |
| countdown | Timer countdown label |
| end-label | Timer end label |
| end-text | Timer ended text |
| Slot scope name | Description |
| --------------- | ------------------------------------------------------------------------ |
| startLabel | Event begin label text |
| endLabel | Event end label text |
| tips | Tips true means countdown till start, false means countdown till end |'begin'
| labelPosition | event label position, or 'end' |
| Slot scope name | Description |
| --------------- | -------------------------------------------------- |
| days | Number of days till event |
| dayTxt | Day label |
| hours | Number of hours till event |
| hourTxt | Hours label |
| minutes | Number of minutes till event |
| minuteTxt | Minutes label |
| seconds | Number of seconds till event |
| secondTxt | Seconds label |
| showDay | display status of day countdown number and text |
| showHour | display status of hour countdown number and text |
| showMinute | display status of minute countdown number and text |
| Slot scope name | Description |
| --------------- | ------------------------------------------------------------------------ |
| startLabel | Event begin label text |
| endLabel | Event end label text |
| tips | Tips true means countdown till start, false means countdown till end |'begin'
| labelPosition | event label position, or 'end' |
| Slot scope name | Description |
| --------------- | ---------------- |
| endText | Timer ended text |
start-time
- type: Number|Stringrequired
- : true
end-time
- type: Number|Stringrequired
- : true
interval
- type: Numberrequired
- : falsedefault
- : 1000
start-label
- type: Stringrequired
- : falsedefault
- : ''
end-label
- type: Stringrequired
- : falsedefault
- : ''
label-position - begin (before countdown) / end (after countdown)
- type: Stringrequired
- : falsedefault
- : 'begin'
end-text
- type: Stringrequired
- : falsedefault
- : 'Event ended!'
day-txt - if pass null, this unit will be hidden
- type: Stringrequired
- : falsedefault
- : ':'
hour-txt - if pass null, this unit will be hidden
- type: Stringrequired
- : falsedefault
- : ':'
seconds-txt - if pass null, this unit will be hidden
- type: Stringrequired
- : falsedefault
- : ':'
seconds-fixed
- type: Stringrequired
- : falsedefault
- : ':'
show-zero - display status of 00
- type: Booleanrequired
- : falsedefault
- : true
start_callback - Event started callback
- type: Functionrequired
- : false
end_callback - Event ended callback
- type: Functionrequired
- : false
If the end-time prop is dynamically generated or 'computed', the initial value will be NaN. This will trigger the end_callback function, which might not be desirable. This can be solved by declaring it this way:
`vue`
:end-time="end_at?end_at:endAt"
...
>
Where end_at is the computed value, and endAt` is a default value.
MIT License