[英]How to use updateLocale in nuxtjs/dayjs?
我想更改荷蘭語語言環境 (nl) 的短工作日。 為此,我需要使用 updateLocale,如下所述: https://day.js.org/docs/en/customization/weekday-abbreviations 。 這是我目前在 nuxt.config.js 中的內容:
modules: [
'@nuxtjs/dayjs',
],
dayjs: {
locales: ['en', 'nl'],
defaultLocale: 'nl',
plugins: [
'updateLocale',
'relativeTime'
],
updateLocale: ('nl', {
weekdaysShort: ['Su', 'Mo', 'Tu', 'WAHH', 'Th', 'Fr', 'Sa']
})
}
不要介意'WAHH'部分,那只是為了測試。 但顯然這是行不通的。 處理這個的正確方法是什么?
在plugins
文件夾中創建一個dayjs.js
文件並在下面編寫代碼。
export default function ({ $dayjs }) {
$dayjs.updateLocale('en', {
relativeTime: {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years',
},
})
}
並將這個插件添加到nuxt.config.js
。
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [ '~/plugins/dayjs'],
最后,將 updateLocale 添加到 nuxt.config.js 中的nuxt.config.js
配置中
...
dayjs: {
locales: ['en'],
defaultLocale: 'en',
defaultTimeZone: 'America/New_York',
plugins: ['timezone', 'relativeTime', 'updateLocale'],
},
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.