微信小程序van-dialog确认验证失败时阻止对话框的关闭
使用官方(Vant Weapp - 轻量、可靠的小程序 UI 组件库)的before-close:
wxml:
<van-dialog use-slot title="名称" show="{{ show }}" show-cancel-button bind:cancel="onClose" bind:confirm="getBackInfo" before-close="{{onBeforeClose}}">自定义内容
</van-dialog>
js:
data: {show: false,onBeforeClose:''
},
getBackInfo() {if (this.data.XXX) {console.log('符合')} else {this.setData({show: true,onBeforeClose: (action) => { new Promise((resolve) => {if (action === 'confirm') { resolve(false)}})}}) console.log('不符合')}
},
onClose() {this.setData({show: false,});
},