diff --git a/index.js b/index.js index 62e1bb2..c91a3f1 100644 --- a/index.js +++ b/index.js @@ -28,17 +28,12 @@ export default { }, localizeText(i18nText) { - // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page const pageNow = this?.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。 - : getCurrentPages()[getCurrentPages().length - 1] - // 支持 localizeText({...}) 来解析参数 + : getCurrentPages()[getCurrentPages().length - 1] // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page + i18nText = i18nText || pageNow.i18nText // 解析输入参数 i18nText,或者 pageNow.i18nText if (i18nText && typeof(i18nText)==='object' && pageNow.$store?.state?.i18n?.mylang) { return i18nText[pageNow.$store.state.i18n.mylang] || '' } - // 支持 localizeText() 来解析 页面.vue 的顶层 i18nText - if (!i18nText && typeof(pageNow.i18nText)==='object' && pageNow.$store?.state?.i18n?.mylang) { - return pageNow.i18nText[pageNow.$store.state.i18n.mylang] || '' - } if (typeof i18nText === 'string'){ return i18nText }