最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vuejs - Element UI - Cannot close dialog with the cross - Stack Overflow

programmeradmin1浏览0评论

I'm facing a little issue using Vuejs 2.3 and Element UI 1.3.1 I would like to be able to close the dialog by clicking on the X but the event does not seem to be caught.

<div id="app">
  <el-dialog title="Shipping address" v-model="showDialog"
    @close="closeDialog()">
    <button @click='cond1 = false'>Close</button>
  </el-dialog>
</div>

var Main = {
    data() {
      return {
        cond1: true,
        cond2: true,
        cond3: true,
      };
    },
    puted : {
        showDialog() {
        return this.cond1 && this.cond2 && this.cond3
        }
    },
    methods: {
        closeDialog() {
          alert('close event')}
    }
  };

/

It is working if I click on the button but not on the cross. Could you explain to me why and what should I do ?

I'm facing a little issue using Vuejs 2.3 and Element UI 1.3.1 I would like to be able to close the dialog by clicking on the X but the event does not seem to be caught.

<div id="app">
  <el-dialog title="Shipping address" v-model="showDialog"
    @close="closeDialog()">
    <button @click='cond1 = false'>Close</button>
  </el-dialog>
</div>

var Main = {
    data() {
      return {
        cond1: true,
        cond2: true,
        cond3: true,
      };
    },
    puted : {
        showDialog() {
        return this.cond1 && this.cond2 && this.cond3
        }
    },
    methods: {
        closeDialog() {
          alert('close event')}
    }
  };

https://jsfiddle/zuL0uqy2/

It is working if I click on the button but not on the cross. Could you explain to me why and what should I do ?

Share Improve this question asked May 10, 2017 at 14:19 Léo CocoLéo Coco 4,28211 gold badges60 silver badges100 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

According to the source, all that happens when you click the close X in element ui is that it emits two events, update:visible and visible-change. You need to listen to one of these events in order to update your data appropriately to close the dialog. You could add a method like this

onVisible(isVisible){
    if (isVisible)
        return
    this.cond1 = false
}

and change your template accordingly.

<el-dialog title="Shipping address" v-model="showDialog"
    @close="closeDialog()" @visible-change="onVisible" >

Example.

It looks like their intention is that you take advantage of sync being added back into Vue and use a visible attribute.

发布评论

评论列表(0)

  1. 暂无评论