From 07c38c1b1b29b38d2f707d01112dd19d527d9c9e Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 30 Jun 2026 14:30:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8D=E5=A4=9A=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E8=AF=AD=E8=A8=80=E5=8C=85=E5=8A=A0=E8=BD=BD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E9=A6=96=E5=B1=8F=E6=B8=B2?= =?UTF-8?q?=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整语言包加载时机,区分H5和小程序/鸿蒙平台: H5 remote-only模式下先await Lang.boot()再挂载Vue避免首屏raw key 小程序/鸿蒙平台同步注册App,Lang.boot()放到App.onLaunch异步执行不阻塞挂载 移除了无用的加载语言包错误日志注释 --- common/js/lang.js | 1 - main.js | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/js/lang.js b/common/js/lang.js index e03ead6..261d155 100644 --- a/common/js/lang.js +++ b/common/js/lang.js @@ -528,7 +528,6 @@ function loadLangPackSync(lang, path) { loadedLangPacks[`${lang}_${path}`] = langData; return langData; } catch (error) { - // console.error(`加载语言包 ${lang}/${path} 失败:`, error); return {}; } } diff --git a/main.js b/main.js index bba1057..ec645ff 100644 --- a/main.js +++ b/main.js @@ -55,10 +55,14 @@ uniStorage(); // 组件已改为按需引入,不再全局注册 +// H5 平台: remote-only 下先 await Lang.boot() 再挂载 Vue,避免首屏 raw key +// 小程序/鸿蒙: 同步注册 App,Lang.boot() 在 App.onLaunch 中异步执行(不阻塞挂载) +// 原因: 小程序/鸿蒙的 App() 必须同步注册,async bootstrap 会导致 App 注册延迟,白屏 + +// #ifdef H5 async function bootstrap() { const isRemoteOnly = langConfig && langConfig.source === 'remote-only'; if (isRemoteOnly) { - // remote-only 模式下必须等 bundle 就绪后再挂载 Vue,避免首屏组件在翻译就绪前渲染 let _hideLoading = false; try { uni.showLoading({ title: '加载中...', mask: true }); @@ -81,5 +85,13 @@ async function bootstrap() { }); app.$mount(); } +bootstrap() +// #endif -bootstrap() \ No newline at end of file +// #ifndef H5 +const app = new Vue({ + ...App, + store +}); +app.$mount(); +// #endif \ No newline at end of file