|
I used to use v-calendar with Vuetify 2 and I'm now migrating the project to Vuetify 3. The codebase calls The example here still uses I am using Vuetify 3.10.2, and this is how the original Vuetify 2 code used to look like: mounted() {
...
this.updateTime = setInterval(() => {
if (this.$refs.calendar) {
this.$refs.calendar.updateTimes()
}
}, 60 * 1000)
...
}That code errors with Vuetify 3: Is there a replacement for Thanks in advance! |
Replies: 2 comments
|
In Vuetify 2, If you need to force the current-time indicator to update (e.g. move the "now" line every minute), you can force a re-render of the calendar by toggling its key: <template>
<v-calendar ref="calendar" :key="calendarKey" />
</template>
<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue'
const calendarKey = ref(0)
let interval
onMounted(() => {
interval = setInterval(() => {
calendarKey.value++
}, 60 * 1000)
})
onBeforeUnmount(() => clearInterval(interval))
</script>Not the most elegant solution, but it works. The key change forces Vue to destroy and recreate the component, which recalculates the current time position. What version of Vuetify 3 are you on? The calendar component went through significant changes — if you're on 3.10.x you might also want to check if 3.7+ (where VCalendar was reintroduced) has any relevant updates in the changelog. |
fixed in v3.11.0 (
c77d2b3)