Skip to content

Commit

Permalink
feat: add UiClock task
Browse files Browse the repository at this point in the history
  • Loading branch information
DvornikovAS authored and DvornikovAS committed Jan 10, 2025
1 parent dc28b22 commit 58b20df
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions 03-components/20-UiClock/UiClock.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import { defineComponent } from 'vue'
import { defineComponent, onMounted, onUnmounted, ref } from 'vue'

export default defineComponent({
name: 'UiClock',

setup() {},
setup() {
const currentTime = ref('')

template: `<div class="clock">10:12:02</div>`,
const updateCurrentTimeValue = () => {
const date = new Date()
currentTime.value = date.toLocaleTimeString(navigator, {
timeStyle: 'medium',
})
}

onMounted(() => {
updateCurrentTimeValue()
setInterval(updateCurrentTimeValue, 1000)

onUnmounted(() => {
clearInterval(updateCurrentTimeValue)
})
})

return {
currentTime,
}
},

template: `<div class="clock">
{{ currentTime }}
</div>`,
})

0 comments on commit 58b20df

Please sign in to comment.