The best way for use Day.js easily in your Nuxt.js project.
$ yarn add @nuxtjs/dayjs # or npm install
export default {
// ...
modules: [
'@nuxtjs/dayjs'
],
// Optional
dayjs: {
locales: ['en', 'ja'],
defaultLocale: 'en',
plugins: [] // 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.
{
"compilerOptions": {
"types": [
"@nuxt/types",
"@nuxtjs/dayjs"
]
}
}
$ git clone https://github.com/nuxt-community/dayjs-module.git
$ cd @nuxtjs/dayjs
$ yarn
MIT @potato4d
This project generated by create-nuxt-module
Author: nuxt-community
Source Code: https://github.com/nuxt-community/dayjs-module
#nuxtjs #vue #vuejs #javascript