Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lintx opened this issue Dec 9, 2024 · 0 comments

Comments

@lintx
Copy link

lintx commented Dec 9, 2024

复现:

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中也会显示为英文

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant