js文件 :
const toast = {
show(options) {
const defaultOptions = {
title: '',
icon: 'none',
duration: 2000,
mask: false
}
const toastOptions = Object.assign({}, defaultOptions, options)
// 处理预设类型
if (toastOptions.type) {
switch (toastOptions.type) {
case 'success':
toastOptions.icon = 'success'
toastOptions.image = '/static/image/success.png'
break
case 'error':
toastOptions.icon = 'error'
toastOptions.image = '/static/image/fial.png'
break
case 'loading':
toastOptions.icon = 'loading'
break
}
}
uni.showToast(toastOptions)
},
// 快捷方法
success(title, duration = 2000) {
this.show({
title,
type: 'success',
duration
})
},
error(title, duration = 2000) {
this.show({
title,
type: 'error',
duration
})
},
loading(title = '加载中...', duration = 60000) {
this.show({
title,
type: 'loading',
duration
})
},
hide() {
uni.hideToast()
}
}
export default toast
man.js 文件
app.config.globalProperties.$toast = toast
页面使用
tcBtn(){
this.$toast.success('测试弹窗')
},
2***@qq.com (作者)
不加image 是正常的,加了image 就会出现这个问题
2025-04-10 16:34