Vue Luxon Plugin

0.10.0 · maintenance · verified Tue Apr 21

Vue Luxon is a plugin for Vue.js (specifically Vue 2) that simplifies date and time formatting and parsing using the Luxon library. It provides a convenient `$luxon` instance method and a `luxon` filter, allowing developers to easily display and manipulate date/time strings within their Vue applications. The current stable version is `0.10.0`. Its release cadence appears infrequent, with significant gaps between updates. Key differentiators include its tight integration with Vue's reactivity system and templating, allowing for simple filter and method usage, and leveraging Luxon's modern, immutable API as an alternative to older libraries like Moment.js. It offers extensive configuration options for input/output formats, timezones, and locales directly within Vue's plugin installation and per-usage.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `vue-luxon` as a Vue 2 plugin, configure global default settings, and use both the `$luxon` instance method and the `luxon` filter for various date and time formatting tasks, including custom formats and relative time. It assumes Luxon is also installed.

import Vue from 'vue';
import VueLuxon from 'vue-luxon';
import { DateTime } from 'luxon'; // Luxon itself must be available

// Install the plugin with custom default settings
Vue.use(VueLuxon, {
  input: {
    zone: 'America/New_York',
    format: 'yyyy-MM-dd HH:mm'
  },
  output: {
    format: 'full',
    locale: 'en-GB'
  }
});

new Vue({
  el: '#app',
  data() {
    return {
      dateTimeString: '2023-01-15 10:30',
      anotherDateTime: '2024-03-20T14:00:00.000Z',
      currentLuxonVersion: DateTime.version
    };
  },
  template: `
    <div id="app">
      <h2>Vue Luxon Example (Luxon v{{ currentLuxonVersion }})</h2>
      <p>Original string: <code>{{ dateTimeString }}</code></p>
      <p>Formatted using $luxon method (default settings, en-GB): <strong>{{ $luxon(dateTimeString) }}</strong></p>
      <p>Formatted using $luxon method (custom output 'short', local zone): <strong>{{ $luxon(anotherDateTime, { output: 'short', output: { zone: 'local' } }) }}</strong></p>
      <p>Formatted using luxon filter (default settings): <strong>{{ anotherDateTime | luxon }}</strong></p>
      <p>Formatted using luxon filter (custom output 'yyyy/MM/dd'): <strong>{{ anotherDateTime | luxon('yyyy/MM/dd') }}</strong></p>
      <p>Relative time ('2024-03-01' relative to now): <strong>{{ $luxon('2024-03-01', 'relative') }}</strong></p>
      <p>Current date/time (with custom input/output): <strong>{{ $luxon("2024-04-21 16:30", { input: { format: "yyyy-MM-dd HH:mm" }, output: "MMMM dd, yyyy 'at' HH:mm" }) }}</strong></p>
    </div>
  `,
  mounted() {
    console.log("Mounted, checking $luxon directly:", this.$luxon(this.dateTimeString));
  }
});

view raw JSON →