背景:uni-app运行在微信小程序时,超过7个字符会进行截取,因此需要使用showModal进行提示
export const showToast = (title : string, icon : "success" | "loading" | "error" | "none" = "none", duration = 2000) => {
if (_glPinia.canToast) {
_glPinia.setCannotToast();
if (title.length > 7) {
uni.showModal({
title: '提示',
content: title,
showCancel: false
})
} else {
uni.showToast({
title: title,
duration: duration,
icon: icon || "none"
})
}
}
}
_glPinia.canToast是放pinia的全局参数,用来控制在当前是否允许弹窗,比如https全局请求的时候,有可能出现一次性出现多个错误提示的情况,通过这个变量来劫持