Update Clock.vue

This commit is contained in:
Jursin 2024-12-02 07:31:36 +08:00 committed by GitHub
parent 91ff4e231b
commit 3f2516fb23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,11 +1,7 @@
<template>
<v-card class="mx-auto" max-width="750">
<v-card-text class="text-center">
<div
:style="{ fontSize: fontSizes[fontSizeIndex] }"
class="display-1 font-weight-bold"
@click="cycleFontSize"
>
<div class="display-1 font-weight-bold" @click="cycleFontSize">
{{ formattedTime }}
</div>
</v-card-text>
@ -17,23 +13,28 @@ import { ref, onMounted } from 'vue';
import { useIntervalFn } from '@vueuse/core';
import moment from 'moment';
// 使ref
const formattedTime = ref('');
const fontSizeIndex = ref(2);
const fontSizes = ['4rem', '6rem', '8rem'];
const fontSizeIndex = ref(2); // 7rem
const fontSizes = ['3rem', '5rem', '7rem']; //使
//
onMounted(() => {
updateTime();
});
const formatDateTime = (isoString: moment.MomentInput) => moment(isoString).format('HH:mm:ss');
//
function updateTime() {
const now = new Date();
formattedTime.value = formatDateTime(now);
}
//
useIntervalFn(updateTime, 250);
//
function cycleFontSize() {
fontSizeIndex.value = (fontSizeIndex.value + 1) % fontSizes.length;
}
@ -41,7 +42,6 @@ function cycleFontSize() {
<style scoped>
.display-1 {
margin-top: 30px;
margin-bottom: 30px;
font-size: v-bind(fontSizes[fontSizeIndex]); /* 动态绑定字体大小 */
}
</style>