fix: language switch

This commit is contained in:
Alisa | Side.one 2023-05-05 15:13:14 +08:00
parent 0540ae3b96
commit 02cc6ee176

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { Icon } from '@iconify/vue';
import { defineEmits, ref } from 'vue'
import { defineEmits, ref, watch } from 'vue'
import type { Anchor } from 'vuetify/lib/components';
import type { I18nLanguage } from '@layouts/types';
@ -17,16 +17,15 @@ interface Props {
location?: Anchor;
}
let { locale } = useI18n({ useScope: 'global' });
watch(locale, (val) => {
let locale = ref(useI18n({ useScope: 'global' }).locale)
watch(locale, (val: string) => {
document.documentElement.setAttribute('lang', val as string);
});
let currentLang = ref(localStorage.getItem('lang') || 'en');
function changeLang(lang: string){
locale = lang
locale.value = lang
currentLang.value = lang
emit('change', lang)
}