@@ -30,7 +30,7 @@ const getParent = (getContainer: GetContainer) => {
30
30
}
31
31
if ( getContainer ) {
32
32
if ( typeof getContainer === 'string' ) {
33
- return document . querySelectorAll ( getContainer ) [ 0 ] ;
33
+ return document . querySelectorAll ( getContainer ) [ 0 ] as HTMLElement ;
34
34
}
35
35
if ( typeof getContainer === 'function' ) {
36
36
return getContainer ( ) ;
@@ -68,9 +68,10 @@ export default defineComponent({
68
68
container . value ?. parentNode ?. removeChild ( container . value ) ;
69
69
container . value = null ;
70
70
} ;
71
+ let parent : HTMLElement = null ;
71
72
const attachToParent = ( force = false ) => {
72
73
if ( force || ( container . value && ! container . value . parentNode ) ) {
73
- const parent = getParent ( props . getContainer ) ;
74
+ parent = getParent ( props . getContainer ) ;
74
75
if ( parent ) {
75
76
parent . appendChild ( container . value ) ;
76
77
return true ;
@@ -123,11 +124,14 @@ export default defineComponent({
123
124
[ ( ) => props . visible , ( ) => props . getContainer ] ,
124
125
( [ visible , getContainer ] , [ prevVisible , prevGetContainer ] ) => {
125
126
// Update count
126
- if ( supportDom && getParent ( props . getContainer ) === document . body ) {
127
- if ( visible && ! prevVisible ) {
128
- openCount += 1 ;
129
- } else if ( init ) {
130
- openCount -= 1 ;
127
+ if ( supportDom ) {
128
+ parent = getParent ( props . getContainer ) ;
129
+ if ( parent === document . body ) {
130
+ if ( visible && ! prevVisible ) {
131
+ openCount += 1 ;
132
+ } else if ( init ) {
133
+ openCount -= 1 ;
134
+ }
131
135
}
132
136
}
133
137
@@ -158,8 +162,8 @@ export default defineComponent({
158
162
} ) ;
159
163
160
164
onBeforeUnmount ( ( ) => {
161
- const { visible, getContainer } = props ;
162
- if ( supportDom && getParent ( getContainer ) === document . body ) {
165
+ const { visible } = props ;
166
+ if ( supportDom && parent === document . body ) {
163
167
// 离开时不会 render, 导到离开时数值不变,改用 func 。。
164
168
openCount = visible && openCount ? openCount - 1 : openCount ;
165
169
}
0 commit comments