配置 el-date-picker

问题描述 投票:0回答:2

有人知道如何在 element-plus 中配置 el-date-picker 来设置一周的第一天吗?

文档说它可以通过 day.js 配置,但不能在 element 中使用配置 day.js 。

到目前为止我已经做到了。

import de from 'element-plus/es/locale/lang/de';

const i18n = createI18n({
    legacy: false,
    locale: 'de',
    messages: {
        'de': messagesDe
    },
    datetimeFormats: {
        'de': {
            short: {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit'
            },
            long: {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit'
            }
        }
    },
});

app.use(ElementPlus, {
   locale: de,
});
app.use(i18n);

谢谢您的帮助。

vue.js vuejs3 date-formatting element-plus
2个回答
1
投票

dayjs#215

中描述的解决方法也适用于 Element Plus。

例如,要将星期一设置为

de
语言环境的一周第一天,请在
de
之外创建一个
dayjs.Ls
对象,并设置
weekStart=1
:

// main.js
import dayjs from 'dayjs'

dayjs.Ls.de ??= {}
dayjs.Ls.de.weekStart = 1

演示


0
投票

对我来说,仅在 main.ts 中使用此配置:

import 'dayjs/locale/ru' // locale will imported inside dayjs.Ls(for datepicker use)
import ru from 'element-plus/lib/locale/lang/ru' // global locale for app
    
app.use(ElementPlus, { locale: ru })

dayjs 语言环境文档的链接

© www.soinside.com 2019 - 2024. All rights reserved.