diff --git a/src/shared/i18n/index.ts b/src/shared/i18n/index.ts index 46af083..14f732b 100644 --- a/src/shared/i18n/index.ts +++ b/src/shared/i18n/index.ts @@ -28,6 +28,10 @@ export function setLocale(code: string) { if (locales.some(l => l.code === code)) { locale.value = code localStorage.setItem('locale', code) + // 动态更新 HTML 的 lang 属性 + if (typeof document !== 'undefined') { + document.documentElement.lang = code + } } } @@ -42,4 +46,8 @@ export function initLocale() { if (saved && locales.some(l => l.code === saved)) { locale.value = saved } + // 初始化时设置 HTML 的 lang 属性 + if (typeof document !== 'undefined') { + document.documentElement.lang = locale.value + } } \ No newline at end of file diff --git a/src/views/HomePage.vue b/src/views/HomePage.vue index 997f2a7..e84671c 100644 --- a/src/views/HomePage.vue +++ b/src/views/HomePage.vue @@ -1199,22 +1199,40 @@ onUnmounted(() => {