Commit ea1335dc by luyt

feat:修复GLDialog添加到body的问题

1 parent e5da3922
......@@ -171,7 +171,7 @@
<el-button plain @click="testDialog3">dialog(中)无按钮</el-button>
<el-button plain @click="testBeforeDialog">之前小弹窗</el-button>
<!-- :content="'hello HelloWorld'" -->
<GLDialog :mode="mode" bigTitle="大标题" :hasFooter="hasFooter" :type="'error'" @onOk="handleOk" @onCancel="handleCancel" :visible.sync="dialogShow">
<GLDialog :append-to-body="true" :mode="mode" bigTitle="大标题" :hasFooter="hasFooter" :type="'error'" @onOk="handleOk" @onCancel="handleCancel" :visible.sync="dialogShow">
<div>
<div>这是一段信息</div>
<div>这是一段信息</div>
......@@ -240,7 +240,7 @@
<el-button type="primary" size="small" @click="dialogShow = false">确定123</el-button>
</span> -->
</GLDialog>
<GLDialog :mode="mode" title="提示" :hasFooter="hasFooter" :type="'error'" :content="'hello HelloWorld'" @onOk="handleOk" @onCancel="handleCancel" :visible.sync="dialogShow2"></GLDialog>
<GLDialog :append-to-body="true" :mode="mode" title="提示中" :hasFooter="hasFooter" :type="'error'" :content="'hello HelloWorld'" @onOk="handleOk" @onCancel="handleCancel" :visible.sync="dialogShow2"></GLDialog>
<GLDialog title="提示123" :mode="mode" :hasFooter="hasFooter" :type="'info'" :content="'hello HelloWorld'" @onOk="handleOk" @onCancel="handleCancel" :visible.sync="dialogShow1"></GLDialog>
<!-- <GLDialog title="提示123" :mode="mode" :hasFooter="hasFooter" :type="'info'" @onOk="handleOk" @onCancel="handleCancel" :visible.sync="dialogShow1">
<div>hello</div>
......
<template>
<div class="gl-dialog-wrap " :class="mode" :id="idDom">
<div class="gl-dialog-wrap " :class="mode" :id="idDom" >
<el-dialog v-bind="$attrs" v-on="$listeners">
<template v-slot:title>
<!-- 标题插槽 -->
......@@ -88,6 +88,11 @@ export default {
type: String,
// `success` / `info` / `warning` / `error`
default: ''
},
// 是否添加到body
appendToBody:{
type: Boolean,
default: false
}
},
data() {
......@@ -100,6 +105,9 @@ export default {
document.addEventListener('keyup', (e)=>{
this.keyupHook(e)
});
if (this.appendToBody) {
document.body.appendChild(this.$el);
}
},
computed: {
okName: function() {
......@@ -204,6 +212,9 @@ export default {
document.removeEventListener('keyup',(e)=>{
this.keyupHook(e)
})
if (this.appendToBody && this.$el && this.$el.parentNode) {
this.$el.parentNode.removeChild(this.$el);
}
}
}
</script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!