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
| <script> export default { name: 'downTime',
props: { endTime: { type: Number }, startTime: { type: Number }, endMsg: { type: String } },
data () { return { isShow: false, clocker: '', timeObj: null, myDay: 0, myHours: 0, myMinutes: 0, mySeconds: 0 } }, computed: { getHours1 () { return this.myHours < 10 ? 0 : parseInt((this.myHours % 100) / 10) }, getHours2 () { return parseInt(this.myHours % 10) }, getMinutes1 () { return this.myMinutes < 10 ? 0 : parseInt((this.myMinutes % 100) / 10) }, getMinutes2 () { return parseInt(this.myMinutes % 10) }, getSeconds1 () { return this.mySeconds < 10 ? 0 : parseInt((this.mySeconds % 100) / 10) }, getSeconds2 () { return parseInt(this.mySeconds % 10) } }, mounted () { }, methods: { option () { let timeLag = (this.endTime - this.startTime) / 1000 const add = num => { return num < 10 ? '0' + num : num } const timeFunction = () => { const time = timeLag-- this.timeObj = { seconds: Math.floor(time % 60), minutes: Math.floor(time / 60) % 60, hours: Math.floor(time / 60 / 60) % 24, days: Math.floor(time / 60 / 60 / 24) } this.myDay = `${add(this.timeObj.days)}` this.myHours = `${add(this.timeObj.hours)}` this.myMinutes = `${add(this.timeObj.minutes)}` this.mySeconds = `${add(this.timeObj.seconds)}` if (time <= 0) { this.isShow = true this.clocker = this.endMsg clearInterval(go) } } timeFunction() const go = setInterval(() => { timeFunction() }, 1000) } }, watch: { endTime: { handler (newName, oldName) { this.option() }, immediate: true, deep: true } } } </script>
|