From 09b82d03df06f62b37d044bb4d586bc75175602e Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Wed, 26 Nov 2025 16:18:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(js=E5=85=A5=E5=8F=A3=E6=96=87=E4=BB=B6):?= =?UTF-8?q?=20=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E6=9C=89=E6=97=A0=E4=BB=8Eapp=E4=BC=A0=E8=BF=87=E6=9D=A5?= =?UTF-8?q?=E7=9A=84=E8=AF=AD=E8=A8=80=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index b2862f3..12ac1e5 100644 --- a/src/main.js +++ b/src/main.js @@ -5,7 +5,7 @@ import { smartImage } from './directives/smartImage.js' import { createPinia } from 'pinia' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' import { createApp } from 'vue' -import i18n, { initI18n } from './locales/i18n' +import i18n, { initI18n, setLocale } from './locales/i18n' import App from './App.vue' import router from './router' @@ -33,6 +33,14 @@ app.use(pinia) // 然后初始化 i18n(此时 Pinia 已可用) // 获取 langStore 并传递给 initI18n const langStore = useLangStore() // 直接使用 import 的函数 + +// 检测URL参数并设置语言 +const urlParams = new URLSearchParams(window.location.search) +const langParam = urlParams.get('lang') +if (langParam) { + setLocale(langStore, langParam) +} + initI18n(langStore) // 最后使用 i18n