Using Fullcalendar with Vue.js, I'm passing the initial events from a variable, but I need that after this variable is updated, the events were updated in the calendar also. The documentation seems to be clear about that:
But I've tried this and nothing happens, the events keeps as the first renderization.
Also I've looked in many SO related answers about this topic but most of them are applied with JQuery which is not my case.
I can't figure out how to aply this in a correct way.
Thanks in advance for your attention...
My code to create the calendar:
<FullCalendar :options="calendarOptions" ref="fullCalendar"/>
data() {
return {
calendarOptions: {
firstDay: new Date().getDay(),
plugins: [timeGridPlugin, interactionPlugin],
headerToolbar: {
left: '',
center: 'title',
right: 'prev,next'
},
initialView: 'timeGridWeek',
slotMinTime: "09:00:00",
slotMaxTime: "20:00:00",
height: "1070px",
expandRows: true ,
dayHeaderFormat: { weekday: 'narrow', day: 'numeric' },
events: displayEvents
},
...
The function that update the variable:
getEvents() {
this.displayEvents = [
{
id: 1,
title: "TEST1",
start: "2021-03-29 09:00:00",
end: "2021-03-29 11:00:00",
backgroundColor: "#FF5733"
},
{
id: 2,
title: "TEST2",
start: "2021-03-29 10:00:00",
end: "2021-03-29 11:05:00",
backgroundColor: "#0053B8"
},
]
let calendarApi = this.$refs.fullCalendar.getApi()
calendarApi('refetchEvents')
this.$refs.fullCalendar('refetchEvents')
}
(displayEvents came from another javascript file utils.js, and after execute the function it is modified)
UPDATE:
I found that I was calling the .fullCalendar('refetchEvents')
method in an incorrect way. Now I'm calling it as it:
let calendarApi = this.$refs.fullCalendar.getApi()
calendarApi.refetchEvents()
But still the changes aren't reflected in the calendar after this.