Skip to content

Commit

Permalink
fix(useElementSize): should reset value while element unmounted (vite…
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Feb 13, 2022
1 parent aba020f commit 7b40091
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/core/useElementSize/index.ts
@@ -1,8 +1,8 @@
import { ref } from 'vue-demi'
import { ref, watch } from 'vue-demi'
import type { MaybeElementRef } from '../unrefElement'
import type { ResizeObserverOptions } from '../useResizeObserver'
import { useResizeObserver } from '../useResizeObserver'

import { unrefElement } from '../unrefElement'
export interface ElementSize {
width: number
height: number
Expand Down Expand Up @@ -32,7 +32,10 @@ export function useElementSize(
},
options,
)

watch(() => unrefElement(target), (ele) => {
width.value = ele ? initialSize.width : 0
height.value = ele ? initialSize.height : 0
})
return {
width,
height,
Expand Down

0 comments on commit 7b40091

Please sign in to comment.