修复: 设置页渲染崩溃(AppearanceSection 静态 import @/i18n 触发 TDZ)
- AppearanceSection 去掉 import i18n from '@/i18n',改用 useI18n() 获取 locale - 根因:@/i18n 模块顶层调 useAppSettingsStore().get(),打包后初始化顺序冲突 - 这是设置页 + AI 独立窗口反复报 Cannot access 'u' before initialization 的根因
This commit is contained in:
@@ -43,8 +43,8 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, watch, onMounted, useTemplateRef } from 'vue'
|
import { reactive, watch, onMounted, useTemplateRef } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useAppSettingsStore } from '@/stores/appSettings'
|
import { useAppSettingsStore } from '@/stores/appSettings'
|
||||||
import i18n from '@/i18n'
|
|
||||||
import SettingRow from './SettingRow.vue'
|
import SettingRow from './SettingRow.vue'
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@@ -53,6 +53,7 @@ import SettingRow from './SettingRow.vue'
|
|||||||
// 阶段5:SettingRow 封装行布局,控件变更后调 markSaved 显"已保存"
|
// 阶段5:SettingRow 封装行布局,控件变更后调 markSaved 显"已保存"
|
||||||
// ============================================================
|
// ============================================================
|
||||||
const appSettings = useAppSettingsStore()
|
const appSettings = useAppSettingsStore()
|
||||||
|
const { locale } = useI18n()
|
||||||
|
|
||||||
const settings = reactive({
|
const settings = reactive({
|
||||||
theme: appSettings.get<string>('df-theme', 'dark'),
|
theme: appSettings.get<string>('df-theme', 'dark'),
|
||||||
@@ -107,7 +108,7 @@ watch(() => settings.streamingMd, (val) => {
|
|||||||
watch(() => settings.language, (val) => {
|
watch(() => settings.language, (val) => {
|
||||||
void appSettings.set('df-language', val)
|
void appSettings.set('df-language', val)
|
||||||
// 同步 i18n 实例,让界面立即跟随语言切换
|
// 同步 i18n 实例,让界面立即跟随语言切换
|
||||||
i18n.global.locale.value = val as 'zh-CN' | 'en'
|
locale.value = val as 'zh-CN' | 'en'
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user