封装文件utils/common
// 不带图标的轻提示
export function showTip(title, duration = 1500) {
uni.showToast({
title,
icon: 'none',
duration
})
}
// 带图标的提示
export function showToast(title, type, successCallback) {
uni.showToast({
title,
icon: type,
duration: 2500,
success: () => {
setTimeout(function() {
successCallback()
}, 100)
}
})
}
// 一键复制
export function copyModal(value) {
uni.setClipboardData({
data: value, //要被复制的内容
success: () => { //复制成功的回调函数
uni.showToast({ //提示
icon: 'none',
title: '复制成功'
})
}
});
}
main.js引入
import { showToast, showTip, copyModal } from '@/utils/common';
Vue.prototype.$showToast = showToast
Vue.prototype.$showTip = showTip
Vue.prototype.$copyModal = copyModal
使用
// 一键复制
copyHandle(ordeSN){
this.$copyModal(ordeSN)
},
// 弹框提示
this.$showTip('弹框提示')