2022-09-09 22:41:50 +00:00
|
|
|
<template>
|
|
|
|
|
<div>{{ clock }}</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-09-09 23:14:03 +00:00
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
2022-09-10 02:11:36 +00:00
|
|
|
import { DateTime } from "luxon";
|
2022-09-09 22:41:50 +00:00
|
|
|
|
2022-09-09 23:14:03 +00:00
|
|
|
@Component
|
|
|
|
|
export default class ClockDisplay extends Vue {
|
|
|
|
|
private clock = "";
|
2022-09-10 02:11:36 +00:00
|
|
|
private interval?: number;
|
2022-09-09 22:41:50 +00:00
|
|
|
|
2022-09-09 23:14:03 +00:00
|
|
|
@Prop()
|
|
|
|
|
format!: string;
|
2022-09-09 22:41:50 +00:00
|
|
|
|
2022-09-10 02:11:36 +00:00
|
|
|
private created(): void {
|
|
|
|
|
this.interval = setInterval((): void => {
|
|
|
|
|
this.clock = DateTime.now()
|
|
|
|
|
.setLocale(navigator.language)
|
|
|
|
|
.toFormat(this.format);
|
|
|
|
|
}, 1000);
|
2022-09-09 23:14:03 +00:00
|
|
|
}
|
2022-09-09 22:41:50 +00:00
|
|
|
|
2022-09-10 02:11:36 +00:00
|
|
|
private beforeDestroy(): void {
|
|
|
|
|
// prevent memory leak
|
|
|
|
|
clearInterval(this.interval);
|
2022-09-09 23:14:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-09 22:41:50 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
</style>
|