|
4 | 4 | v-model="value" |
5 | 5 | v-model:period="period" |
6 | 6 | format="crontab" |
7 | | - locale="en" |
| 7 | + :locale="locale" |
| 8 | + :key="locale" |
8 | 9 | @error="error = $event" |
9 | 10 | > |
10 | 11 | </cron-light> |
|
14 | 15 | </div> |
15 | 16 | <br /> |
16 | 17 | Error: {{ error }} |
17 | | - <div> |
18 | | - <button @click="toggleDarkMode" class="cl-btn" style="margin-top: 1em"> |
| 18 | + <div style="margin-top: 1em"> |
| 19 | + <button @click="toggleDarkMode" class="cl-btn"> |
19 | 20 | Switch to {{ isDark ? 'Light' : 'Dark' }} Mode |
20 | 21 | </button> |
| 22 | + <button @click="switchLocale" class="cl-btn">Locale: {{ locale }}</button> |
21 | 23 | </div> |
22 | 24 | </div> |
23 | 25 | </template> |
24 | 26 |
|
25 | | -<script lang="ts"> |
| 27 | +<script lang="ts" setup> |
26 | 28 | import CronLight from '@/components/cron-light.vue' |
| 29 | +import { ref, watch } from 'vue' |
| 30 | +
|
| 31 | +const value = ref(undefined) |
| 32 | +const period = ref('month') |
| 33 | +const error = ref('') |
| 34 | +const isDark = ref(false) |
| 35 | +const locale = ref('en') |
| 36 | +
|
| 37 | +watch(value, (value) => { |
| 38 | + console.log('value changed: ' + value) |
| 39 | +}) |
| 40 | +watch(period, (value) => { |
| 41 | + console.log('period changed: ' + value) |
| 42 | +}) |
| 43 | +
|
| 44 | +function updateValue(evt: any) { |
| 45 | + value.value = evt.target.value |
| 46 | +} |
| 47 | +
|
| 48 | +function toggleDarkMode() { |
| 49 | + const body = document.querySelector('body') |
| 50 | + isDark.value = body?.classList.toggle('dark') ?? false |
| 51 | +} |
27 | 52 |
|
28 | | -export default { |
29 | | - components: { |
30 | | - CronLight, |
31 | | - }, |
32 | | - data: () => { |
33 | | - return { |
34 | | - value: undefined, |
35 | | - period: 'month', |
36 | | - error: '', |
37 | | - isDark: false, |
38 | | - } |
39 | | - }, |
40 | | - watch: { |
41 | | - value: function (value) { |
42 | | - console.log('value changed: ' + value) |
43 | | - }, |
44 | | - period: function (value) { |
45 | | - console.log('period changed: ' + value) |
46 | | - }, |
47 | | - }, |
48 | | - methods: { |
49 | | - updateValue(evt: any) { |
50 | | - this.value = evt.target.value |
51 | | - }, |
52 | | - toggleDarkMode() { |
53 | | - const body = document.querySelector('body') |
54 | | - this.isDark = body?.classList.toggle('dark') ?? false |
55 | | - }, |
56 | | - }, |
| 53 | +function switchLocale() { |
| 54 | + const locales = ['en', 'de'] |
| 55 | + const i = (locales.indexOf(locale.value) + 1) % locales.length |
| 56 | + locale.value = locales[i] |
57 | 57 | } |
58 | 58 | </script> |
59 | 59 |
|
|
0 commit comments