Я использую компонент fullcalendar- vue. Мой сценарий - планирование событий, когда фоновые события являются недоступными временными интервалами, но вы можете добавлять события в календарь в доступных временных интервалах.
Два источника событий:
- связанный реактивный массив для событий добавлен в календарь, когда пользователь щелкает функцию события
- для извлечения фоновых событий, когда пользователь щелкает в следующем месяце
Как настроить эти два источника событий?
<FullCalendar editable="true" ref="calendar"
:header="{
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth, timeGridWeek'
}"
:plugins="plugins"
:weekends="true"
:event-sources="eventSources"
@dateClick="handleDateClick"/>
// I have tried adding the event sources as data: and computed:
computed: {
eventSources: function () {
return [
{
id: "events",
// this is the array of editable events.
// how do I access this in @dateClick?
events: []
},
{
id: "background",
// these are the background events
events: (info) => {
// ... encode start/end dates in URL, send via axios promise ...
axios.get(url)
.then(response => {
var calendarEvents = [];
// ... load up the array of background events and return them ...
return calendarEvents;
})
.catch(error => {
console.log(error);
});
}
}
];
}
},
methods:
handleDateClick: function (item) {
let calendarApi = this.$refs.calendar.getApi();
var source = calendarApi.getEventSourceById('events');
// this is where I'm stuck. Need to add this event to events[]
// the following doesn't work because there's no access to the array in the source object
source.events.push(
{
'title': 'New Event',
'start': item.date,
'duration': '01:00:00'
});
}