Mobile-friendly Datetime Picker for Vue 2

1.0.0-beta.14 · active · verified Sun Apr 19

vue-datetime is a mobile-friendly datetime picker component designed for Vue 2 applications. Currently in beta (v1.0.0-beta.14), it provides robust functionalities for selecting dates, datetimes, or times, alongside comprehensive internationalization (i18n) support and the capability to disable specific date ranges. The library depends on Luxon for its underlying date and time manipulation and optionally utilizes `weekstart` to determine the first day of the week, though locale-based auto-detection is available. Distribution occurs via npm, enabling integration within modern JavaScript bundler workflows like Webpack or Rollup, or direct inclusion in browser environments via CDN. While it is under active development, users should be aware of its beta status, which implies that API changes may occur prior to a stable 1.0 release. Its key differentiators include its focus on mobile usability and a highly customizable picker flow and display format, making it suitable for responsive web applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install, globally register, and use the `vue-datetime` component in a basic Vue 2 application with `v-model` binding for both datetime and date modes.

<template>
  <div id="app">
    <h1>Vue Datetime Picker Demo</h1>
    <datetime v-model="selectedDate" type="datetime" input-id="my-datetime-picker"></datetime>
    <p>Selected Datetime (ISO 8601): <strong>{{ selectedDate }}</strong></p>
    <p>Using type="date":</p>
    <datetime v-model="selectedDateOnly" type="date"></datetime>
    <p>Selected Date: <strong>{{ selectedDateOnly }}</strong></p>
  </div>
</template>

<script>
import Vue from 'vue';
import { Datetime } from 'vue-datetime';
import 'vue-datetime/dist/vue-datetime.css';

// Luxon is a peer dependency but doesn't need to be imported directly here.
// Ensure it's installed: npm install luxon

// Register the component globally
Vue.use(Datetime);

export default {
  name: 'App',
  data() {
    return {
      selectedDate: new Date().toISOString(), // Initialize with current ISO string
      selectedDateOnly: new Date().toISOString().split('T')[0] + 'T00:00:00.000Z'
    };
  }
};
</script>

<style>
body {
  font-family: Arial, sans-serif;
  margin: 20px;
  background-color: #f8f8f8;
}
h1 {
  color: #333;
  margin-bottom: 20px;
}
p {
  margin-top: 15px;
  font-size: 1.1em;
}
strong {
  color: #007bff;
}
/* Basic styling for the picker input */
#my-datetime-picker {
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1em;
  width: 250px;
  margin-bottom: 20px;
}
</style>

view raw JSON →