Skip to content

Commit

Permalink
feat(useElementSize): get value in onMounted hook
Browse files Browse the repository at this point in the history
  • Loading branch information
chaii3 committed Sep 1, 2023
1 parent 48f4c6e commit 8487d2a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/useElementSize/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { tryOnMounted } from '@vueuse/shared'
import { computed, ref, watch } from 'vue-demi'
import type { MaybeComputedElementRef } from '../unrefElement'
import type { UseResizeObserverOptions } from '../useResizeObserver'
Expand Down Expand Up @@ -61,6 +62,14 @@ export function useElementSize(
options,
)

tryOnMounted(() => {
const ele = unrefElement(target)
if (ele) {
width.value = 'offsetWidth' in ele ? ele.offsetWidth : initialSize.width
height.value = 'offsetHeight' in ele ? ele.offsetHeight : initialSize.height
}
})

watch(
() => unrefElement(target),
(ele) => {
Expand Down

0 comments on commit 8487d2a

Please sign in to comment.