This commit is contained in:
Jörn-Michael Miehe 2022-09-10 02:19:45 +00:00
parent cd2cf8ca08
commit 0a19286261
2 changed files with 11 additions and 12 deletions

View file

@ -1,5 +1,5 @@
<template> <template>
<div>{{ clock }}</div> <div>{{ formatted }}</div>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -7,23 +7,22 @@ import { Component, Prop, Vue } from "vue-property-decorator";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
@Component @Component
export default class ClockDisplay extends Vue { export default class Clock extends Vue {
private clock = ""; private formatted = "";
private interval?: number; private interval?: number;
@Prop() @Prop()
format!: string; public format!: string;
private created(): void { public created(): void {
this.interval = setInterval((): void => { this.interval = setInterval((): void => {
this.clock = DateTime.now() this.formatted = DateTime.now()
.setLocale(navigator.language) .setLocale(navigator.language)
.toFormat(this.format); .toFormat(this.format);
}, 1000); }, 1000);
} }
private beforeDestroy(): void { public beforeDestroy(): void {
// prevent memory leak
clearInterval(this.interval); clearInterval(this.interval);
} }
} }

View file

@ -3,19 +3,19 @@
<v-spacer /> <v-spacer />
<v-col> <v-col>
<ClockDisplay format="DDD" /> <Clock format="DDD" />
<ClockDisplay format="T" /> <Clock format="T" />
</v-col> </v-col>
</v-toolbar> </v-toolbar>
</template> </template>
<script> <script>
import { Component, Vue } from "vue-property-decorator"; import { Component, Vue } from "vue-property-decorator";
import ClockDisplay from "./ClockDisplay.vue"; import Clock from "./Clock.vue";
@Component({ @Component({
components: { components: {
ClockDisplay, Clock,
}, },
}) })
export default class TitleBar extends Vue {} export default class TitleBar extends Vue {}