(iView)View UI框架中的Modal对话框阻止点击确定按钮时关闭

使用官方的代码,value(可用v-model双向绑定)控制modal框的显示隐藏,会出现只要点击了确定按钮,v-model绑定的值自动变为false,关闭modal框,想要的效果:点击确定按钮判断条件决定modal框是否关闭

解决方案一:

<template>
    <div>
        <button style="margin-left: 10px;" @click="btn">demo按钮</button>
        <Modal 
            :value="modalConfig.modalShow"
            title="新增"
            :transfer="false"
            :mask-closable="false"
            :width="400"
            @on-ok="Submit"
            @on-cancel="cancel"
            :loading="modalConfig.loading"
        >
            <Input v-model.trim="age"></Input>
        </Modal>
    </div>
</template>

<script>
    export default{
        data(){
            return {
                age:'男',
                modalConfig:{
                    modalShow:false,
                    loading:true
                }
            }
        },
        methods:{
            btn(){
                this.modalConfig.modalShow = true
            },
            Submit(){
                if(this.age !== '男'){
                    this.modalConfig.loading = false;
                    this.$nextTick(() => {
                        this.modalConfig.loading = true;
                    })
                    this.$Message.error("输入框必须为男!");
                }else{
                    this.modalConfig.modalShow = false
                    this.$Message.error("成功");
                }
            },
            cancel(){
                this.modalConfig.modalShow = false
            }
        }
    }
</script>

<style>

</style>

解决方案二:

<template>
    <div>
        <button style="margin-left: 10px;" @click="btn">demo按钮</button>
        <Modal 
            v-model="modalConfig.modalShow"
            title="新增"
            :transfer="false"
            :mask-closable="false"
            :width="400"
        >
            <Input v-model.trim="age"></Input>
            <div slot="footer">
				<Button type="primary" @click="cancel">取消</Button>
				<Button type="primary" @click="submit">确定</Button>
			</div>
        </Modal>
    </div>
</template>

<script>
    export default{
        data(){
            return {
                age:'男',
                modalConfig:{
                    modalShow:false,
                }
            }
        },
        methods:{
            btn(){
                this.modalConfig.modalShow = true
            },
            submit(){
                if(this.age !== '男'){
                    this.$Message.error("输入框必须为男!");
                }else{
                    this.modalConfig.modalShow = false
                    this.$Message.error("成功");
                }
            },
            cancel(){
                this.modalConfig.modalShow = false
            }
        }
    }
</script>

<style>

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值