forked from getanwar/vuejs-countdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountdown.vue
110 lines (89 loc) · 2.02 KB
/
Countdown.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<ul class="vue-countdown">
<li>
<p class="digit">{{ days | twoDigits }}</p>
<p class="text">days</p>
</li>
<li>
<p class="digit">{{ hours | twoDigits }}</p>
<p class="text">hours</p>
</li>
<li>
<p class="digit">{{ minutes | twoDigits }}</p>
<p class="text">Min</p>
</li>
<li>
<p class="digit">{{ seconds | twoDigits }}</p>
<p class="text">Sec</p>
</li>
</ul>
</template>
<script>
import Vue from 'vue'
Vue.filter('twoDigits', (value) => {
if ( value.toString().length <= 1 ) {
return '0'+value.toString()
}
return value.toString()
})
export default {
props: ['deadline'],
data() {
return {
now: Math.trunc((new Date()).getTime() / 1000),
date: null
}
},
mounted() {
this.date = Math.trunc(Date.parse(this.deadline) / 1000)
setInterval(() => {
this.now = Math.trunc((new Date()).getTime() / 1000)
}, 1000)
},
computed: {
seconds() {
return Math.trunc(this.date - this.now) % 60
},
minutes() {
return Math.trunc((this.date - this.now) / 60) % 60
},
hours() {
return Math.trunc((this.date - this.now) / 60 / 60) % 24
},
days() {
return Math.trunc((this.date - this.now) / 60 / 60 / 24)
}
}
}
</script>
<style lang="sass" rel="stylesheet/sass">
.vue-countdown
padding: 0
margin: 0
li
display: inline-block
margin: 0 8px
text-align: center
position: relative
&:after
content: ':'
position: absolute
top: 0
right: -13px
font-size: 32px
&:first-of-type
margin-left: 0
&:last-of-type
margin-right: 0
&:after
content: ''
.digit
font-size: 32px
font-weight: 600
line-height: 1.4
margin-bottom: 0
.text
text-transform: uppercase
margin-bottom: 0
font-size: 10px
</style>