SSR-safe time element for Nuxt 3
Install and add nuxt-time to your nuxt.config.
# Whichever matches your package manager
pnpm add -D nuxt-time
npm install -D nuxt-time
yarn add -D nuxt-time
export default defineNuxtConfig({
modules: ['nuxt-time'],
})
To use, you can use the <NuxtTime> component anywhere in your app. It accepts datetime and locale (optional) properties, along with any property accepted by Intl.DateTimeFormat (see MDN reference).
<template>
<!-- Date.now() will safely respect the date rendered on the server, not the client-side hydration. -->
<!-- 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>
corepack enable (use npm i -g corepack for Node.js < 16.10)pnpm installpnpm dev:preparepnpm dev to start playground in development modeMade with ❤️
Published under the MIT License.