Skip to content

Commit 1f429c1

Browse files
committed
fix: body scroll when open modal #1472
1 parent 31dda9e commit 1f429c1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

components/vc-dialog/DialogWrap.jsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ import ContainerRender from '../_util/ContainerRender';
33
import getDialogPropTypes from './IDialogPropTypes';
44
import { getStyle, getClass } from '../_util/props-util';
55
const IDialogPropTypes = getDialogPropTypes();
6+
let openCount = 0;
67
const DialogWrap = {
78
props: {
89
...IDialogPropTypes,
910
visible: IDialogPropTypes.visible.def(false),
1011
},
1112
data() {
13+
openCount = this.visible ? openCount + 1 : openCount;
1214
this.renderComponent = () => {};
1315
this.removeContainer = () => {};
1416
return {};
1517
},
16-
18+
watch: {
19+
visible(val, preVal) {
20+
openCount = val && !preVal ? openCount + 1 : openCount - 1;
21+
},
22+
},
1723
beforeDestroy() {
1824
if (this.visible) {
25+
openCount = openCount ? openCount - 1 : openCount;
1926
this.renderComponent({
2027
afterClose: this.removeContainer,
2128
visible: false,
@@ -29,14 +36,15 @@ const DialogWrap = {
2936
},
3037
methods: {
3138
getComponent(extra = {}) {
32-
const { $attrs, $listeners, $props, $slots } = this;
39+
const { $attrs, $listeners, $props, $slots, getContainer } = this;
3340
const { on, ...otherProps } = extra;
3441
const dialogProps = {
3542
props: {
3643
...$props,
3744
dialogClass: getClass(this),
3845
dialogStyle: getStyle(this),
3946
...otherProps,
47+
getOpenCount: getContainer === false ? () => 2 : () => openCount,
4048
},
4149
attrs: $attrs,
4250
ref: '_component',

0 commit comments

Comments
 (0)