Vue Datepicker UI
Vue Datepicker UI is an open-source, lightweight datepicker component designed for seamless integration into Vue.js applications. It currently supports both Vue 2 (versions 2.x, with 2.3.0 being the latest minor release) and Vue 3 (versions 3.x, with 3.1.1 being the latest minor release, accessible via the `@vue3` npm tag). The library maintains a moderate release cadence, providing minor feature enhancements and bug fixes, as seen with recent updates like 2.3.0 and 3.1.1 which added a `reset` event and `showPickerInital` property respectively. A key differentiator is its modularity; style files are optional, allowing developers to completely customize the component's appearance or integrate it into existing design systems without conflicts. Furthermore, it boasts a smaller bundle size since version 2.0.0, contributing to improved application performance. The component provides essential date selection functionalities, including single and multi-picker modes, with features like a clear date button for enhanced user experience.
Common errors
-
Failed to resolve component: Datepicker (or VueDatepicker)
cause The component was imported but not correctly registered globally or locally in your Vue application.fixEnsure the component is registered in your `components` option (for Options API) or imported and used in `<script setup>` (for Composition API in Vue 3, if using `@vuepic/vue-datepicker`). Example: `components: { Datepicker }`. -
[Vue warn]: Component provided is not a function or object.
cause You are likely trying to use the Vue 2 version of `vue-datepicker-ui` with a Vue 3 application, or vice-versa, causing incompatibility.fixVerify your installed `vue-datepicker-ui` package version matches your Vue.js runtime version. For Vue 2, use `vue-datepicker-ui@^2`. For Vue 3, use `vue-datepicker-ui@vue3` or consider `npm install @vuepic/vue-datepicker` for dedicated Vue 3 support. -
Datepicker component appears unstyled or with incorrect layout.
cause The default CSS file was not imported, or conflicting styles are overriding it.fixAdd `import 'vue-datepicker-ui/lib/vuedatepickerui.css';` to your main JavaScript/TypeScript entry point or the component where the Datepicker is used. Ensure there are no higher-priority conflicting styles.
Warnings
- breaking The `vue-datepicker-ui` package has distinct major versions for Vue 2 and Vue 3. Version 2.x is for Vue 2, while version 3.x (published under the `@vue3` tag) is for Vue 3. Using the incorrect version with your Vue runtime will lead to runtime errors.
- gotcha The default styles (`vuedatepickerui.css`) are optional. If you do not import them, the component will be unstyled. If you import them, you can customize them using CSS variables.
- gotcha An issue with `v-model` not correctly binding in certain scenarios was fixed in version 2.2.0. Older versions might exhibit unexpected behavior with two-way data binding.
Install
-
npm install vue-datepicker-ui -
yarn add vue-datepicker-ui -
pnpm add vue-datepicker-ui
Imports
- Datepicker
const Datepicker = require('vue-datepicker-ui');import Datepicker from 'vue-datepicker-ui';
- CSS Styles
import 'vue-datepicker-ui/lib/vuedatepickerui.css';
- Vue 3 Import (via @vuepic/vue-datepicker)
import { VueDatePicker } from '@vuepic/vue-datepicker'; import '@vuepic/vue-datepicker/dist/main.css';
Quickstart
<template>
<div id="app">
<h1>Select a Date</h1>
<Datepicker v-model="selectedDate" :clear-button="true" date-format="DD.MM.YYYY"></Datepicker>
<p>Selected Date: {{ selectedDate ? new Date(selectedDate).toLocaleDateString() : 'None' }}</p>
<h2>Date Range Selection</h2>
<Datepicker v-model="dateRange" range></Datepicker>
<p>Range: {{ dateRange && dateRange.from && dateRange.to ? `${new Date(dateRange.from).toLocaleDateString()} - ${new Date(dateRange.to).toLocaleDateString()}` : 'None' }}</p>
</div>
</template>
<script>
import Datepicker from 'vue-datepicker-ui';
import 'vue-datepicker-ui/lib/vuedatepickerui.css';
export default {
name: 'App',
components: {
Datepicker
},
data() {
return {
selectedDate: null,
dateRange: { from: null, to: null }
};
},
mounted() {
// Example: Set initial date to today
this.selectedDate = new Date();
}
};
</script>
<style>
/* Optional: Add some basic styling or overrides */
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>