This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
generated from rocketbase-io/ts-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.vue
73 lines (61 loc) · 1.8 KB
/
clock.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
<template>
<div :class="classes">
<span class="example-clock__hours" v-text="hours" />
<span class="example-clock__separator">:</span>
<span class="example-clock__minutes" v-text="minutes" />
<span class="example-clock__separator">:</span>
<span class="example-clock__seconds" v-text="seconds" />
<span class="example-clock__separator" v-if="ms" >.</span>
<span class="example-clock__millis" v-if="ms" v-text="millis" />
</div>
</template>
<script lang="ts">
import { BProp, ClassesKebap, Component, Data, Every, Vue } from "@rocketbase/vue-extra-decorators";
@Component({})
export default class ExampleClock extends Vue {
// Define a boolean property, defaulting to false
@BProp()
private ms!: boolean;
// Convert class name and returned key names to kebap-case and prefix
// all returned members with the class name and "--"
// e.g. { "example-clock": true, "example-clock--ms": false }
@ClassesKebap()
private get classes() {
const { ms } = this;
return { ms };
}
// Define a data property, defaulting to a new Date object.
@Data({ default: () => new Date() })
private time!: Date;
private get hours() {
return this.time.toString().padStart(2, "0");
}
private get minutes() {
return this.time.toString().padStart(2, "0");
}
private get seconds() {
return this.time.toString().padStart(2, "0");
}
private get millis() {
return this.time.toString().padStart(3, "0");
}
// Execute this method every 100 ms until the component is destroyed
@Every(100)
private onTick() {
this.time = new Date();
}
}
</script>
<style>
.example-clock {
font-family: monospace;
color: #333333;
border: 2px solid #333333;
font-size: 20px;
padding: 5px 10px;
}
.example-clock__millis {
font-size: 16px;
color: #555555;
}
</style>