diff --git a/packages/uni-api/src/service/ui/locale.ts b/packages/uni-api/src/service/ui/locale.ts index d8a769a81e139d29e30b050bc50ce4438ff2aa5f..11221d3688df975a5f918d814fb4f024c9ba457e 100644 --- a/packages/uni-api/src/service/ui/locale.ts +++ b/packages/uni-api/src/service/ui/locale.ts @@ -25,8 +25,6 @@ export const setLocale = defineSyncApi( const oldLocale = getApp().$vm.$locale if (oldLocale !== locale) { getApp().$vm.$locale = locale - // 执行 uni.onLocaleChange - UniServiceJSBridge.invokeOnCallback(API_ON_LOCALE_CHANGE, { locale }) if (__PLATFORM__ === 'app') { const pages = getCurrentPages() pages.forEach((page) => { @@ -38,6 +36,8 @@ export const setLocale = defineSyncApi( }) weex.requireModule('plus').setLanguage(locale) } + // 执行 uni.onLocaleChange + UniServiceJSBridge.invokeOnCallback(API_ON_LOCALE_CHANGE, { locale }) return true } return false diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 366ffcfae4f405f9b94bbe57f1c6234d08bb99f3..301e8b6c10215fa91120a72d0006d8c36055e32f 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -10470,9 +10470,7 @@ function createPageHeadSearchInputTsx(navigationBar, { "style": { color }, - "placeholder-style": { - color: placeholderColor - }, + "placeholder-style": "color: " + placeholderColor, "class": "uni-page-head-search-input", "confirm-type": "search", "onClick": onClick @@ -10481,9 +10479,7 @@ function createPageHeadSearchInputTsx(navigationBar, { "style": { color }, - "placeholder-style": { - color: placeholderColor - }, + "placeholder-style": "color: " + placeholderColor, "class": "uni-page-head-search-input", "confirm-type": "search", "onFocus": onFocus, diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 5392cefc942f2b2e7a0dfc65d66f4f7d441e933f..43a9ce4b189e2c7f25434c055281c4f755323923 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -20828,9 +20828,7 @@ function createPageHeadSearchInputTsx(navigationBar, { "style": { color }, - "placeholder-style": { - color: placeholderColor - }, + "placeholder-style": "color: " + placeholderColor, "class": "uni-page-head-search-input", "confirm-type": "search", "onClick": onClick @@ -20839,9 +20837,7 @@ function createPageHeadSearchInputTsx(navigationBar, { "style": { color }, - "placeholder-style": { - color: placeholderColor - }, + "placeholder-style": "color: " + placeholderColor, "class": "uni-page-head-search-input", "confirm-type": "search", "onFocus": onFocus, diff --git a/packages/uni-h5/src/framework/components/page/pageHead.tsx b/packages/uni-h5/src/framework/components/page/pageHead.tsx index 60214df3a6653f4b7ac53c776ab572220c694fca..b285bf67ce1c631b2f22272e9517567ec48394e8 100644 --- a/packages/uni-h5/src/framework/components/page/pageHead.tsx +++ b/packages/uni-h5/src/framework/components/page/pageHead.tsx @@ -220,7 +220,7 @@ function createPageHeadSearchInputTsx( appVm.$locale, (newLocale) => { - i18n.setLocale(newLocale); - }); + // 需要保证 watch 的触发在组件渲染之前 + if (appVm.$watchLocale) { + // vue2 + appVm.$watchLocale((newLocale) => { + i18n.setLocale(newLocale); + }); + } + else { + appVm.$watch(() => appVm.$locale, (newLocale) => { + i18n.setLocale(newLocale); + }); + } } function initVueI18n(locale, messages = {}, fallbackLocale, watcher) { // 兼容旧版本入参 diff --git a/packages/uni-i18n/dist/uni-i18n.es.js b/packages/uni-i18n/dist/uni-i18n.es.js index d4d1d6331893ba7849f54fc18d7afb11fadd6b68..1c7f5e9e14ead4ed0e8f6b12b048f517ec6b661c 100644 --- a/packages/uni-i18n/dist/uni-i18n.es.js +++ b/packages/uni-i18n/dist/uni-i18n.es.js @@ -219,9 +219,18 @@ class I18n { const ignoreVueI18n = true; function watchAppLocale(appVm, i18n) { - appVm.$watch(() => appVm.$locale, (newLocale) => { - i18n.setLocale(newLocale); - }); + // 需要保证 watch 的触发在组件渲染之前 + if (appVm.$watchLocale) { + // vue2 + appVm.$watchLocale((newLocale) => { + i18n.setLocale(newLocale); + }); + } + else { + appVm.$watch(() => appVm.$locale, (newLocale) => { + i18n.setLocale(newLocale); + }); + } } function initVueI18n(locale, messages = {}, fallbackLocale, watcher) { // 兼容旧版本入参 diff --git a/packages/uni-i18n/src/vue-i18n.ts b/packages/uni-i18n/src/vue-i18n.ts index c89ba49c904dd270fdc94c56b6494404dac52428..fc88b6e2b49926d1293121feddd19176fc07d0f0 100644 --- a/packages/uni-i18n/src/vue-i18n.ts +++ b/packages/uni-i18n/src/vue-i18n.ts @@ -14,12 +14,20 @@ type Interpolate = ( ) => string function watchAppLocale(appVm: any, i18n: I18n) { - appVm.$watch( - () => appVm.$locale, - (newLocale: string) => { + // 需要保证 watch 的触发在组件渲染之前 + if (appVm.$watchLocale) { + // vue2 + appVm.$watchLocale((newLocale: string) => { i18n.setLocale(newLocale) - } - ) + }) + } else { + appVm.$watch( + () => appVm.$locale, + (newLocale: string) => { + i18n.setLocale(newLocale) + } + ) + } } // function getDefaultLocale() {