Skip to content

Commit

Permalink
feat(useElementSize): stop function (#3367)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
chaii3 and antfu committed Nov 9, 2023
1 parent dc6f2e8 commit 5f545be
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/core/useElementSize/index.ts
Expand Up @@ -25,7 +25,7 @@ export function useElementSize(
const width = ref(initialSize.width)
const height = ref(initialSize.height)

useResizeObserver(
const { stop: stop1 } = useResizeObserver(
target,
([entry]) => {
const boxSize = box === 'border-box'
Expand Down Expand Up @@ -58,17 +58,23 @@ export function useElementSize(
options,
)

watch(
const stop2 = watch(
() => unrefElement(target),
(ele) => {
width.value = ele ? initialSize.width : 0
height.value = ele ? initialSize.height : 0
},
)

function stop() {
stop1()
stop2()
}

return {
width,
height,
stop,
}
}

Expand Down

0 comments on commit 5f545be

Please sign in to comment.