Skip to content

使用leftWindow/topWindow/rightWindow会导致一些bug,比如i18n默认语言读取为en #5243

@lintx

Description

@lintx

复现:

npx degit dcloudio/uni-preset-vue#vite my-vue3-project
cd .\my-vue3-project\
pnpm i
pnpm add @dcloudio/uni-ui sass

按官方教程添加vue.config.js和easycom配置
然后添加leftWindow设置(修改为topWindow或rightWindow也一样)

"leftWindow": {
	"path": "pages/index/index.vue" // 指定 leftWindow 页面文件
}

再在index.vue中添加uni-search-bar组件:
<uni-search-bar :focus="true"></uni-search-bar>

最后跑起来
pnpm run dev:h5
在浏览器中可以看到uni-search-bar组件显示为英文
经过调试,发现原因为在left/top/rightWindow优先main初始化,uni-search-bar使用initVueI18n(messages)初始化i18n
@dcloudio/uni-i18n中会走到getDefaultLocale,然后在当前环境中uniglobal都是未定义,直接return LOCALE_EN
根本原因还是此时读取不到uni变量,由此可以判断除了i18n,可能还会有其他相关问题
该问题会导致共用组件在main中也会表现出一样的问题,因为初始化代码只会执行一次,比如uni-search-bar虽然在window和main中都使用了,但是由于语言代码在初始化阶段就已经调用完了,后续是复用,所以在main中也会显示为英文

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions