Skip to content

Model对话框点击确定后iview会自动关闭窗口 #597

Closed
@awoter

Description

@awoter

环境:iview 2.0.0-rc.7 vue:2.2.0

问题描述:在某个页面需打开一个Model,然后这个Model里有一个Form表单,点击确定时我需要先校验表单数据是否输入正确,不确定则不希望关闭窗口;(问题是:只要点击确认 loading :false 情况下iview默认就把this.visible = false 窗口就关闭了)

希望楼主优化啊;

看了源码后,目前我这做法是:
Form校验不通过,则:
this.$refs.endorseModel.visible = true;
this.endorseModel = true;
这样窗口就不会关闭;

Activity

eeve

eeve commented on Apr 6, 2017

@eeve

+1 昨天正好碰到这个问题

miaosun009

miaosun009 commented on Apr 6, 2017

@miaosun009

我也遇到这个问题

icarusion

icarusion commented on Apr 7, 2017

@icarusion
Contributor

看了一下,还是使用不当的问题。loading 要动态控制。

<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;
                    });
                }, 2000);
            }
        }
    }
</script>
eeve

eeve commented on Apr 7, 2017

@eeve
<template>
    <div>
        <Button type="primary" @click="modal1 = true">显示对话框</Button>
        <Modal
            v-model="modal1"
            title="普通的Modal对话框标题"
            @on-ok="ok"
            :loading="loading">
            <Form ref="form" :model="form" :rules="rule">
              <Form-item prop="name">
                <Input v-model="form.name"></Input>
              </Form-item>
            </Form>
        </Modal>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                modal1: false,
                loading: true,
                form: {
                  name: ''
                },
                rule: {
                  name: {
                    required: true,
                    min: 4
                  }
                }
            }
        },
        methods: {
          changeLoading() {
            this.loading = false;
            this.$nextTick(() => {
              this.loading = true;
            });
          },
          ok () {
            this.$refs['form'].validate(valid => {
              if(!valid) {
                return this.changeLoading();
              }
              setTimeout(() => {
                this.changeLoading();
                this.modal1 = false;
                this.$Message.success('done');
              }, 1000);
            });
          }
        }
    }
</script>
awoter

awoter commented on Apr 7, 2017

@awoter
Author

@icarusion 嗯,试了下 这种方式确实可以;不过文档上没说明,估计一般不知道用这句:
this.$nextTick(() => { this.loading = true; });

zzzplus

zzzplus commented on Apr 12, 2017

@zzzplus

菜鸟坑提醒:

export default {
	data() {
		return {
			modal: false,
			loading: true // 一定要设置为true,否则第一次提交表单,modal还是会被隐藏
		}
	}
}

我设置loading: false,害我调试了一下午

kakanjau

kakanjau commented on Apr 25, 2017

@kakanjau

在 on-ok 里 return 一个 promise的方式来控制,是不是更合理、直观一些。
虽然通过loading和nextTick配合可以达到目的,但是太绕了,loading属性本身的目的也不是为了这个吧

leixu2txtek

leixu2txtek commented on Jun 29, 2017

@leixu2txtek

看来这个设计确实不符合大众使用的习惯,作者可以考虑优化一下吗?

Ai-010

Ai-010 commented on Jul 7, 2017

@Ai-010

modal 使用起来特别别扭 就这个阻止关闭的这个就设计不好,为什么要强行关闭呢,提供方法出来让开发者自行关闭或许更好

rijn

rijn commented on Jul 7, 2017

@rijn
Contributor

Promise does not make sense to me on this issue. This feature is reasonable that under most of the situations, we wish the modal be closed immediately after clicking the ok button. But we can add a prop autoclose to control whether the modal would be closed when trigger on-ok.

24 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lhywell@lixiaobin-bjhl@yangzhixiao@zzzplus@linanlin

        Issue actions

          Model对话框点击确定后iview会自动关闭窗口 · Issue #597 · iview/iview