改进 showToast,调用getCurrentPages()获取当前页面,使得不需要 call(this, ...)
This commit is contained in:
parent
ad75cd1aee
commit
76a58883be
@ -1,17 +0,0 @@
|
|||||||
module.exports = function showToast({type, icon, image, title, duration}){
|
|
||||||
if (this.$refs && this.$refs.toast) {
|
|
||||||
this.$refs.toast.open({type, content:title, duration})
|
|
||||||
}else {
|
|
||||||
// #ifndef APP-PLUS
|
|
||||||
if (!image){
|
|
||||||
image = `../static/Common.${type?type:'info'}.png`
|
|
||||||
}
|
|
||||||
uni.showToast({icon, image, title, duration})
|
|
||||||
// #endif
|
|
||||||
// #ifdef APP-PLUS
|
|
||||||
if (uni.getSystemInfoSync().platform==='android') {
|
|
||||||
uni.showToast({icon:'none', title, duration})
|
|
||||||
}
|
|
||||||
// #endif
|
|
||||||
}
|
|
||||||
}
|
|
20
index.js
20
index.js
@ -73,4 +73,24 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showToast({type, icon, image, title, duration}){
|
||||||
|
let pageStack = getCurrentPages()
|
||||||
|
let pageNow = pageStack[pageStack.length-1]
|
||||||
|
if (pageNow.$refs && pageNow.$refs.toast) {
|
||||||
|
pageNow.$refs.toast.open({type, content:title, duration})
|
||||||
|
}else {
|
||||||
|
// #ifndef APP-PLUS
|
||||||
|
if (!image){
|
||||||
|
image = `../static/Common.${type?type:'info'}.png`
|
||||||
|
}
|
||||||
|
uni.showToast({icon, image, title, duration})
|
||||||
|
// #endif
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
if (uni.getSystemInfoSync().platform==='android') {
|
||||||
|
uni.showToast({icon:'none', title, duration})
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user