集成 vue-i18n 支持国际化

This commit is contained in:
就眠儀式
2022-02-09 17:40:33 +08:00
parent 4325ca3bff
commit 70d4f66b96
7 changed files with 62 additions and 7 deletions

View File

@@ -1,25 +1,31 @@
<script lang="ts">
import { watch } from '@vue/runtime-core';
import { useI18n } from 'vue-i18n';
export default {
name: "lay-config-provider",
};
</script>
<script setup lang="ts">
const { locale } = useI18n();
export interface LayConfigProviderProps {
local?: string;
locale?: string;
theme?: string;
themeVariable?: object;
}
const props = withDefaults(defineProps<LayConfigProviderProps>(),
{
local: 'zh_cn',
locale: 'en_US',
theme: 'light',
}
);
const changeLocale = (lang: string) => {
locale.value = lang
}
const changeTheme = (theme: string) => {
document.body.removeAttribute("lay-theme");
document.body.setAttribute("lay-theme", theme);
@@ -36,6 +42,10 @@ const changeThemeVariable = (vars: any) => {
}
};
watch(() => props.locale, (lang) => {
changeLocale(lang)
},{immediate: true})
watch(() => props.theme, (theme) => {
changeTheme(theme);
},{immediate: true});