console
var app = new Vue({
el: '#app',
data() {
return {
dialogVisible: false,
mousedownCls: [],
mouseupCls: []
}
},
methods: {
dialogMousedown(e) {
this.mousedownCls = [...e.target.classList]
},
dialogMouseup(e) {
this.mouseupCls = [...e.target.classList]
},
beforeDialogClose(done) {
const isWrapper = this.mousedownCls.includes('el-dialog__wrapper') && this.mouseupCls.includes('el-dialog__wrapper')
const isClose = this.mousedownCls.includes('el-dialog__close') && this.mouseupCls.includes('el-dialog__close')
if (isWrapper || isClose) {
done()
}
}
}
});
<div id="app">
<el-button type="text"
@click="dialogVisible = true">
点击打开 Dialog
</el-button>
<el-dialog title="提示"
:visible.sync="dialogVisible"
:before-close="beforeDialogClose"
@mousedown.native="dialogMousedown"
@mouseup.native="dialogMouseup">
<span>这是一段信息</span>
<div slot="footer"
class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary"
@click="dialogVisible = false">确 定</el-button>
</div>
</el-dialog>
</div>