问题:modal框作为表单验证,当表单内容通不过校验时,点击“确认”按钮希望不关闭modal框

解决方案:

关键一步操作  this.$nextTick(() => { this.loading = true; });

<template>
    <div>
        <Button type="primary" @click="modal1 = true">显示对话框</Button>
        <Modal
            v-model="modal1"
            title="Modal"
            @on-ok="ok"
            :loading="loading">
            <p>对话框内容</p>
            <p>对话框内容</p>
            <p>对话框内容</p>
        </Modal>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                modal1: false,
                loading: true
            }
        },
        methods: {
            ok () {
                this.$Message.info('异步验证数据');
                setTimeout(() => {
                    this.loading = false;
                    this.$nextTick(() => {
                        this.loading = true;
                    });
                }, 1000);
            }
        }
    }
</script>

 

Logo

前往低代码交流专区

更多推荐