Vue Cal
Vue Cal is a lightweight and highly customizable full calendar component for Vue.js applications, currently in its stable version 4.10.2. A key differentiator is its 'no dependency' philosophy, aiming for minimal footprint and maximum flexibility. It offers various views (day, week, month, year), robust event management including adding, editing, dragging, and resizing events, and extensive customization options through slots and CSS. While version 4.x is considered stable and suitable for production, it is no longer actively maintained. Development has shifted to version 5, which is a complete rewrite available under the `@next` tag and housed in a new repository. Users should be aware that future updates and new features will be for v5, and migrating from v4 to v5 will involve breaking changes due to its rebuilt architecture. The project emphasizes separating logic and styles, providing minimal CSS for easy overriding.
Common errors
-
Failed to resolve module specifier "vue-cal" (or similar 'module not found' error)
cause The `vue-cal` package is not correctly installed, or the import path is incorrect, or bundler configuration issue.fixEnsure `vue-cal` is installed (`npm install vue-cal` or `yarn add vue-cal`). Verify the import statement `import VueCal from 'vue-cal'` is correct and that your bundler supports ESM. -
The calendar component renders with zero height or is not visible.
cause Vue Cal needs a defined height from its parent container or directly on the component to render properly.fixApply a `height` style to the `<vue-cal>` component or its immediate parent element (e.g., `<div style="height: 600px;"><VueCal /></div>` or `<VueCal style="height: 600px;" />`). -
Uncaught SyntaxError: Cannot use import statement outside a module (or similar CommonJS errors)
cause Attempting to use `require('vue-cal')` in a modern Vue 3 project, which primarily uses ES Modules.fixSwitch to ES module imports: `import VueCal from 'vue-cal';` and ensure your project's build setup (e.g., `package.json` type, bundler config) supports ES Modules. -
Type '...' is not assignable to type 'VueCalEvent'. Property '...' is missing in type '...'.
cause When using TypeScript, event objects or `VueCal` props are not correctly typed according to `vue-cal`'s declarations.fixRefer to the `vue-cal` documentation or its TypeScript declaration files (`.d.ts`) for the correct interface for event objects and component props. Ensure all required properties are present and correctly typed.
Warnings
- breaking Vue Cal v4.x is no longer actively maintained. While stable, new features and ongoing support have shifted to Vue Cal v5. Users planning long-term projects or requiring the latest features should consider migrating to v5, which is a complete rewrite and introduces breaking changes.
- gotcha Vue Cal requires its parent container or the component itself to have a defined height. If no height is set, the calendar will not render correctly (e.g., appear with zero height).
- deprecated Vue Cal's legacy branch for Vue 2 support (`npm i vue-cal@legacy`) has reached End-Of-Life and will not receive further updates or support.
- gotcha The calendar's default CSS is minimal and intentionally not styled with `!important` flags, encouraging users to easily override styles. Direct modification of the component's internal styles can lead to unexpected behavior during updates.
- gotcha When handling events, especially during drag-and-drop operations, the `originalEvent` property in emitted event objects (e.g., `@event-drop`) might return date values as strings instead of `Date` objects, requiring manual parsing.
Install
-
npm install vue-cal -
yarn add vue-cal -
pnpm add vue-cal
Imports
- VueCal
const VueCal = require('vue-cal')import VueCal from 'vue-cal'
- styles
import 'vue-cal/dist/vuecal.scss'
import 'vue-cal/dist/vuecal.css'
- Localized Messages
import 'vue-cal/dist/i18n/fr.js'
Quickstart
<template>
<div class="calendar-container">
<VueCal
class="vuecal--blue-theme"
:selected-date="new Date()"
:time-step="30"
:disable-views="['years', 'year']"
:events="events"
@ready="onCalendarReady"
@event-create="onEventCreate"
/>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import VueCal from 'vue-cal';
import 'vue-cal/dist/vuecal.css';
const events = ref([
{
start: new Date(new Date().setHours(10, 0, 0, 0)).toISOString(),
end: new Date(new Date().setHours(11, 30, 0, 0)).toISOString(),
title: 'Meeting with John',
content: 'Discuss project roadmap.',
class: 'leisure'
},
{
start: new Date(new Date().setHours(14, 0, 0, 0)).toISOString(),
end: new Date(new Date().setHours(15, 0, 0, 0)).toISOString(),
title: 'Team Sync',
content: 'Weekly team catch-up.',
class: 'work'
}
]);
function onCalendarReady() {
console.log('Vue Cal is ready!');
}
function onEventCreate(event: any) {
console.log('Event created:', event);
// In a real app, you'd typically add the event to your `events` array or backend.
}
</script>
<style>
.calendar-container {
height: 600px; /* Crucial: Vue Cal needs a defined height */
max-width: 900px;
margin: auto;
}
.vuecal__event.leisure {
background-color: #a3c4f3;
border: 1px solid #75a7f0;
color: #fff;
}
.vuecal__event.work {
background-color: #90ee90;
border: 1px solid #6cdd6c;
color: #fff;
}
</style>