feat: add switch with zh|en
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createApp, watch } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import App from './App.vue'
|
||||
import './assets/main.css' // 引入新的全局样式文件
|
||||
import './registerServiceWorker'
|
||||
import router from './router'
|
||||
import i18n from './i18n'
|
||||
import { useLanguageStore } from './stores/language'
|
||||
import './assets/main.css'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
|
||||
app.use(pinia)
|
||||
app.use(router)
|
||||
app.use(i18n)
|
||||
|
||||
const languageStore = useLanguageStore(pinia)
|
||||
|
||||
// 监听 Pinia store 中的 locale 变化,并更新 i18n
|
||||
watch(
|
||||
() => languageStore.locale,
|
||||
(newLocale) => {
|
||||
i18n.global.locale.value = newLocale
|
||||
}
|
||||
)
|
||||
|
||||
// 初始化时,确保 i18n 的 locale 与 store 同步
|
||||
i18n.global.locale.value = languageStore.locale
|
||||
|
||||
app.mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user