Created
October 6, 2019 12:37
-
-
Save leemartin/ff2a64a6116e938a526939becaa6821a to your computer and use it in GitHub Desktop.
Luxon Vue Countdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<time>{{ remaining }}</time> | |
</template> | |
<script> | |
import { DateTime, Duration } from 'luxon' | |
export default{ | |
data() { | |
return { | |
now: DateTime.local(), | |
counting: null | |
} | |
}, | |
computed: { | |
remaining() { | |
return this.end.diff(this.now).toFormat('dd hh mm ss') | |
} | |
}, | |
created() { | |
this.end = DateTime.fromObject({ | |
year: 2019, | |
month: 11, | |
day: 3, | |
zone: "America/New_York" | |
}) | |
}, | |
mounted() { | |
this.counting = setInterval(() => { | |
this.now = DateTime.local() | |
if(this.now > this.end) { | |
clearInterval(this.counting) | |
} | |
}, 1000) | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice example!