From 47ead8acbd351e762881ef3ed33b4df0625f996b Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Tue, 21 Sep 2021 19:45:40 +0800 Subject: [PATCH] u --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 63f5f44..fb16893 100644 --- a/index.js +++ b/index.js @@ -33,13 +33,13 @@ module.exports = { }, thisPage(){ - return getCurrentPages()[getCurrentPages().length - 1] + return this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。 + : getCurrentPages()[getCurrentPages().length - 1] }, localizeText(i18nText) { // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page - const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 而不是 getCurrentPages[...] 去访问。 - : getCurrentPages()[getCurrentPages().length - 1] + const thisPage = this.thisPage() if (i18nText && typeof(i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) { return i18nText[thisPage.$store.state.i18n.mylang] || '' } @@ -53,8 +53,7 @@ module.exports = { }, localeText() { - const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 而不是 getCurrentPages[...] 去访问。 - : getCurrentPages()[getCurrentPages().length - 1] // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page + const thisPage = this.thisPage() // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page return thisPage.i18nText[thisPage.$store.state.i18n.mylang] }, @@ -382,7 +381,7 @@ module.exports = { }) */ showToast({ tool, type, image, title, duration = 2000, ...rest }) { - let pageNow = this.$store ? this : getCurrentPages().pop() + let pageNow = this.thisPage() if (tool === 'uni' || !(pageNow.$refs && pageNow.$refs.toast)) { // #ifdef APP-PLUS uni.showToast({ icon: 'none', title, duration, ...rest }) @@ -391,6 +390,7 @@ module.exports = { uni.showToast({ icon: 'none', image, title, duration, ...rest }) // #endif } else { + // 根据 html 中不同的组件 而不同。 pageNow.$refs.toast.show({ type, title, duration, ...rest }) } },