fix: body scroll when open modal #1472

pull/1489/head
tanjinzhou 2019-11-29 18:34:41 +08:00
parent 31dda9e9ce
commit 1f429c1e88
1 changed files with 10 additions and 2 deletions

View File

@ -3,19 +3,26 @@ import ContainerRender from '../_util/ContainerRender';
import getDialogPropTypes from './IDialogPropTypes';
import { getStyle, getClass } from '../_util/props-util';
const IDialogPropTypes = getDialogPropTypes();
let openCount = 0;
const DialogWrap = {
props: {
...IDialogPropTypes,
visible: IDialogPropTypes.visible.def(false),
},
data() {
openCount = this.visible ? openCount + 1 : openCount;
this.renderComponent = () => {};
this.removeContainer = () => {};
return {};
},
watch: {
visible(val, preVal) {
openCount = val && !preVal ? openCount + 1 : openCount - 1;
},
},
beforeDestroy() {
if (this.visible) {
openCount = openCount ? openCount - 1 : openCount;
this.renderComponent({
afterClose: this.removeContainer,
visible: false,
@ -29,7 +36,7 @@ const DialogWrap = {
},
methods: {
getComponent(extra = {}) {
const { $attrs, $listeners, $props, $slots } = this;
const { $attrs, $listeners, $props, $slots, getContainer } = this;
const { on, ...otherProps } = extra;
const dialogProps = {
props: {
@ -37,6 +44,7 @@ const DialogWrap = {
dialogClass: getClass(this),
dialogStyle: getStyle(this),
...otherProps,
getOpenCount: getContainer === false ? () => 2 : () => openCount,
},
attrs: $attrs,
ref: '_component',