van-dialog 点击confirm确定时如果不满足条件则不允许关闭
<van-dialog v-model="showDialog" @confirm="confirmFn" @cancel="showDialog = false" title="添加故障现象" show-cancel-button :before-close="onBeforeClose" > <div class="p10"> <van-field v-model="faultPhenomenon" placeholder="请输入" clearable :rules="[{ required: true, message: '请输入故障现象' }]" /> </div> </van-dialog>
onBeforeClose (action, done) {
// 点击了确定按钮
if (action === "confirm") {
if (this.faultPhenomenon == '') {
this.$toast.fail('请输入故障现象');
return
}
// if()...也可以加入一些条件
return done(false);//直接return它即可阻止
}
// 点击了取消按钮
else {
done(true); //关闭弹窗, true可以省略
}
},
// 确定添加故障现象
confirmFn () {
},