Dayjs Module screenshot

Dayjs Module

Author Avatar Theme by Nuxt community
Updated: 22 Mar 2025
261 Stars

Day.js module for your Nuxt 2 project.

Categories

Overview:

The @nuxtjs/dayjs is a module that allows easy integration of the Day.js library into a Nuxt 2 project. This module provides a convenient way to use Day.js functionality within a Nuxt application, and it is compatible with TypeScript.

Features:

  • Easily Integrate Day.js: Register the @nuxtjs/dayjs module to your Nuxt application and access Day.js functionality seamlessly.
  • Use $dayjs on Context and Vue Instance: Access the Day.js library on the Nuxt context and Vue instance using the $dayjs property.
  • Support for TypeScript: TypeScript users can add the relevant types to their “types” array in the tsconfig.json file after the @nuxt/types entry.

Installation:

To install and use the @nuxtjs/dayjs module, follow the steps below:

  1. Register the dayjs module in your Nuxt application.
// nuxt.config.js
module.exports = {
  modules: [
    '@nuxtjs/dayjs',
  ],
}
  1. Access Day.js functionality on the Nuxt context and Vue instance.
  • With Context:

    export default {
      asyncData({ app }) {
        app.$dayjs; // Access Day.js methods through $dayjs property
        // ...
      },
    }
    
  • With Vue instance:

    export default {
      mounted() {
        this.$dayjs; // Access Day.js methods through $dayjs property
        // ...
      },
    }
    
  1. For TypeScript users, add the types to the “types” array in the tsconfig.json file after the @nuxt/types entry.

Summary:

The @nuxtjs/dayjs module provides seamless integration of the Day.js library into a Nuxt 2 project. With this module, developers can easily access Day.js functionality on the Nuxt context and Vue instance. TypeScript users are also supported with type definitions for convenient development. Overall, this module offers a streamlined way to use Day.js in a Nuxt 2 application.