1. 程式人生 > 其它 >element-plus 日曆周國際化不生效問題解決

element-plus 日曆周國際化不生效問題解決

elementJs:

import { createApp, ref } from 'vue'
import ElementPlus from 'element-plus';
import zhLocale from 'element-plus/lib/locale/lang/zh-cn';
import 'dayjs/locale/zh-cn';

ElementPlus.useLang = (app, ref, locale) => {
  const template = (str, option) => {
    if (!str || !option) return str
    
return str.replace(/\{(\w+)\}/g, (_, key) => { return option[key] }) } // 注入全域性屬性,子元件都能通過inject獲取 app.provide('ElLocaleInjection', { lang: ref(locale.name), locale: ref(locale), t: (...args) => { const [path, option] = args let value const array = path.split('.') let current
= locale for (let i = 0, j = array.length; i < j; i++) { const property = array[i] value = current[property] if (i === j - 1) return template(value, option) if (!value) return '' current = value } }, }) } const app = createApp(App); ElementPlus.useLang(app, ref, zhLocale)