feat(js入口文件): 初始化时检测有无从app传过来的语言设置
This commit is contained in:
parent
84be300945
commit
09b82d03df
10
src/main.js
10
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user