u
This commit is contained in:
parent
e7eb619e94
commit
47ead8acbd
12
index.js
12
index.js
@ -33,13 +33,13 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
thisPage(){
|
thisPage(){
|
||||||
return getCurrentPages()[getCurrentPages().length - 1]
|
return this.$store ? this // 对于组件内定义的 i18nText,要使用 this 来获得组建内的 i18nText,而不是 getCurrentPages[...] 去访问全局页面的 i18nText。
|
||||||
|
: getCurrentPages()[getCurrentPages().length - 1]
|
||||||
},
|
},
|
||||||
|
|
||||||
localizeText(i18nText) {
|
localizeText(i18nText) {
|
||||||
// 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
|
// 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
|
||||||
const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 而不是 getCurrentPages[...] 去访问。
|
const thisPage = this.thisPage()
|
||||||
: getCurrentPages()[getCurrentPages().length - 1]
|
|
||||||
if (i18nText && typeof(i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) {
|
if (i18nText && typeof(i18nText)==='object' && thisPage.$store?.state?.i18n?.mylang) {
|
||||||
return i18nText[thisPage.$store.state.i18n.mylang] || ''
|
return i18nText[thisPage.$store.state.i18n.mylang] || ''
|
||||||
}
|
}
|
||||||
@ -53,8 +53,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
localeText() {
|
localeText() {
|
||||||
const thisPage = this.$store ? this // 对于组件内定义的 i18nText,要使用 this 而不是 getCurrentPages[...] 去访问。
|
const thisPage = this.thisPage() // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
|
||||||
: getCurrentPages()[getCurrentPages().length - 1] // 如果直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果通过 this.$T.localeText 访问,那么 this.i18nText 就报错了。因此安全起见,先获取当前 page
|
|
||||||
return thisPage.i18nText[thisPage.$store.state.i18n.mylang]
|
return thisPage.i18nText[thisPage.$store.state.i18n.mylang]
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -382,7 +381,7 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
showToast({ tool, type, image, title, duration = 2000, ...rest }) {
|
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)) {
|
if (tool === 'uni' || !(pageNow.$refs && pageNow.$refs.toast)) {
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
uni.showToast({ icon: 'none', title, duration, ...rest })
|
uni.showToast({ icon: 'none', title, duration, ...rest })
|
||||||
@ -391,6 +390,7 @@ module.exports = {
|
|||||||
uni.showToast({ icon: 'none', image, title, duration, ...rest })
|
uni.showToast({ icon: 'none', image, title, duration, ...rest })
|
||||||
// #endif
|
// #endif
|
||||||
} else {
|
} else {
|
||||||
|
// 根据 html 中不同的组件 <ucToast/> 或 <toast/> 而不同。
|
||||||
pageNow.$refs.toast.show({ type, title, duration, ...rest })
|
pageNow.$refs.toast.show({ type, title, duration, ...rest })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user