第一步
npm i moment
第二步
App.vue文件中添加
<template>
<a-config-provider :locale="locale">
<router-view />
</a-config-provider>
</template>
<script setup lang="ts">
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import enUS from 'ant-design-vue/es/locale/en_US'
import viVN from 'ant-design-vue/es/locale/vi_VN'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import 'dayjs/locale/vi'
import { ref, onMounted } from 'vue'
dayjs.locale('zhCN')
onMounted(() => {
getLocal()
})
const locale = ref<any>()
const getLocal = () => {
let local = localStorage.getItem('kiwi-lang')
switch (local) {
case 'zh-CN':
locale.value = zhCN
dayjs.locale('zh-CN')
break
case 'en-US':
locale.value = enUS
dayjs.locale('en')
break
case 'vi':
locale.value = viVN
dayjs.locale('vi')
break
}
}
</script>
<style scoped>
</style>