0
点赞
收藏
分享

微信扫一扫

uni-app自定义插件挂载到全局

醉东枫 2022-04-01 阅读 81
小程序

以简单的弹窗插件为例子

config.js

const config = {
baseUrl:'http://localhost:8088',//请求的基本路径
modalColor:'#5271FF', //弹窗颜色
}
module.exports = config

message.js

const config = require('./config.js')

var message = {
toast(title, type = 'text') {
if (title.length > 15) {
console.error('toast长度超过15个字符,当前长度为' + title.length)
return
}
var icon = 'none'
if (type) {
switch (type) {
case 'text':
icon = 'none'
break
case 'suc':
icon = 'success'
break
case 'err':
icon = 'error'
break
}
}
uni.showToast({
title,
icon
})
},
confirm(title, confirmColor) {
return new Promise((res, rej) => {
uni.showModal({
title,
cancelColor: '#b6b6b6',
confirmColor: confirmColor || config.modalColor,
success: (result) => {
if (result.cancel) {
rej(result)
} else if (result.confirm) {
res(result)
}
}

})
})
},
async message(content, confrimText) {
return new Promise((res) => {
uni.showModal({
title: '提示',
content,
showCancel: false,
confirmColor: config.modalColor,
success: (result) => {
res(result)
}
})
})
}
}
module.exports = message

main.js 上进行挂载

在这里插入图片描述

举报

相关推荐

0 条评论