当前位置:   article > 正文

原生微信小程序封装模态对话框组件wx.showModal()

wx.showmodal
// 封装 模态对话框 showModal
const modal = ( options = {} ) => {
	return new Promise((resolve) => {
		// 默认参数
		const optinsObj = {
			title: "提示",
			content: "您确定执行该操作吗?",
			confirmColor: "#f3514f",
		}
		// 通过 object.assign 方法将参数进行合并
		const opts = Object.assign({}, optinsObj, options)
		wx.showModal({
			...opts,
			// 成功或失败都会执行回调函数
			complete({ confirm, cancel }){
				confirm && resolve(true)
				cancel && resolve(false)
			}
		})
	})
}

// 将封装的模块挂载到 wx 全局对象身上
wx.modal = modal
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 使用
import './utils/extendApi'
// 模态对话框
async showModal(){
	await wx.modal({ showCancel: false })
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号