时钟功能 hook ,获取当前时分秒、年月日、星期几
import { ref } from 'vue'
import dayjs from 'dayjs'
export function useClock() {const yyyyMMdd = ref(dayjs().format('YYYY-MM-DD'))const HHmmss = ref('')const weekArr = ['日', '一', '二', '三', '四', '五', '六']const week = ref(weekArr[new Date().getDay()])let timer: NodeJS.Timer | null = nullcreateTimer()function createTimer() {clearTimer()timer = setInterval(function () {HHmmss.value = dayjs().format('HH : mm : ss')}, 1000)}function clearTimer() {if (timer) {clearInterval(timer)timer = null}}return { yyyyMMdd, HHmmss, week, clearTimer }
}