danielroe / nuxt-time

⏰ SSR-safe time element for Nuxt 3
MIT License
307 stars 13 forks source link
date nuxt nuxt-module server ssr

Nuxt Time

npm version npm downloads Github Actions Codecov

SSR-safe time element for Nuxt 3

Features

Installation

Install and add nuxt-time to your nuxt.config.

npx nuxi@latest module add time
export default defineNuxtConfig({
  modules: ['nuxt-time'],
})

Usage

To use, you can use the <NuxtTime> component anywhere in your app. It will render a spec-compliant <time> element.

It accepts datetime and locale (optional) properties, along with any property accepted by Intl.DateTimeFormat (see MDN reference). Note: you can provide a Date or number (e.g. Date.now()) via datetime and it will be rendered correctly as an ISO-formatted date.

<template>
  <!--
    Date.now() will safely respect the time on the server, not on the
    client. What's more, there will be no flash between server
    and client locale formatting.
  -->
  <NuxtTime :datetime="Date.now()" second="numeric" month="long" day="numeric" />
</template>

💻 Development

License

Made with ❤️

Published under the MIT License.