The best way to use Day.js easily in your Nuxt 2 project.
Looking for a Nuxt 3 alternative? Try out:
$ yarn add @nuxtjs/dayjs # or npm installexport default { // ... modules: [ '@nuxtjs/dayjs' ], // Optional dayjs: { locales: ['en', 'ja'], defaultLocale: 'en', defaultTimeZone: 'Asia/Tokyo', plugins: [ 'utc', // import 'dayjs/plugin/utc' 'timezone' // import 'dayjs/plugin/timezone' ] // Your Day.js plugin } // ... }with Context
<script> export default { asyncData({ $dayjs }) { return { now: $dayjs().format('YYYY/MM/DD') } } } </script>with Vue instance
<script> export default { data() { return { latestClicked: null } }, methods: { handleClickButton() { this.latestClicked = this.$dayjs().format('YYYY/MM/DD') } } } </script>Add the types to your "types" array in tsconfig.json after the @nuxt/types entry.
For dayjs plugins, add their relative types like dayjs/plugin/_pluginName_.
{ "compilerOptions": { "types": [ "@nuxt/types", "@nuxtjs/dayjs", "dayjs/plugin/relativeTime", ] } }$ git clone https://github.com/nuxt-community/dayjs-module.git $ cd @nuxtjs/dayjs $ yarnMIT @potato4d
This project generated by create-nuxt-module
Thanks goes to these wonderful people (emoji key):
![]() Takuma HANATANI(@potato4d) π» π π π‘ π¬ π | Bryan Daniel Velastegui Lucero π» | Wei π» | γγγγγ π | Daiki Ojima π» |
This project follows the all-contributors specification. Contributions of any kind welcome!
