原生小程序 之 二次封装 van-dialog组件
xDialog
<!--component/xDialog/xDialog.wxml-->
<!-- bind:close="onClose" -->
<van-dialog
use-slot
title="标题"
show="{{ isShow }}"
show-cancel-button
bind:cancel="onCancel"
bind:confirm="onConfirm"
>
<slot></slot>
</van-dialog>
Component({
properties: {
},
data: {
isShow:false,
},
methods: {
show(){
this.setData({
isShow:true,
})
},
hide(){
this.setData({
isShow:false,
})
},
onCancel(){
this.triggerEvent('onCancel','flase')
},
onConfirm(){
this.triggerEvent('onConfirm')
},
}
})
使用 xDialog组件
<!--pages/info/info.wxml-->
<view class="repair">
<!-- dialog 组件使用 -->
<button bindtap="showDailog">显示弹窗</button>
<!-- wx:if="showDialogFlag" -->
<xDialog id="xDialogID" bindonCancel="onCancel" bindonConfirm="onConfirm">
<view>
我是插槽
</view>
</xDialog>
</view>
showDailog(){
this.selectComponent("#xDialogID").show()
},
onCancel(e){
console.log("取消",e.detail);
},
onConfirm(){
console.log("确定");
}