You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
556 B
22 lines
556 B
import { computed, onMounted, onBeforeUnmount, shallowRef } from 'vue'
|
|
|
|
export const useTime = () => {
|
|
const date = shallowRef(new Date())
|
|
const timer = shallowRef()
|
|
|
|
const currentTime = computed(() => {
|
|
return `${date.value.getHours().toString().padStart(2, '0')}:${date.value.getMinutes().toString().padStart(2, '0')}`
|
|
})
|
|
const getDate = () => {
|
|
timer.value = setInterval(() => {
|
|
date.value = new Date()
|
|
}, 60000)
|
|
}
|
|
|
|
onMounted(getDate)
|
|
onBeforeUnmount(() => clearInterval(timer.value))
|
|
|
|
return {
|
|
currentTime
|
|
}
|
|
}
|
|
|