primevue-mirror/components/fullcalendar/FullCalendar.vue

65 lines
1.5 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<div></div>
</template>
<script>
import '@fullcalendar/core/vdom'; // vite support
2022-09-12 10:35:24 +00:00
import { Calendar } from '@fullcalendar/core';
2022-09-06 12:03:37 +00:00
export default {
name: 'FullCalendar',
props: {
events: Array,
options: null
},
calendar: null,
watch: {
events(value) {
if (value && this.calendar) {
this.calendar.removeAllEventSources();
this.calendar.addEventSource(value);
}
},
options(value) {
if (value && this.calendar) {
for (let prop in value) {
this.calendar.setOption(prop, value[prop]);
}
}
}
},
mounted() {
if (this.$el.offsetParent) {
this.initialize();
}
},
updated() {
if (!this.calendar && this.$el.offsetParent) {
this.initialize();
}
},
beforeUnmount() {
if (this.calendar) {
this.calendar.destroy();
this.calendar = null;
}
},
methods: {
initialize() {
2022-09-12 10:35:24 +00:00
let defaultConfig = { themeSystem: 'standard' };
let config = this.options ? { ...this.options, ...defaultConfig } : defaultConfig;
2022-09-14 11:26:01 +00:00
2022-09-06 12:03:37 +00:00
this.calendar = new Calendar(this.$el, config);
this.calendar.render();
if (this.events) {
this.calendar.removeAllEventSources();
this.calendar.addEventSource(this.events);
}
}
}
2022-09-12 10:35:24 +00:00
};
2022-09-06 12:03:37 +00:00
</script>
2022-09-12 10:35:24 +00:00
<style></style>