Skip to content

Commit

Permalink
fix(useElementBounding): call update on mounted (#626) (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hebilicious committed May 3, 2022
1 parent 8eaead8 commit dccd1f3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/core/useElementBounding/index.ts
@@ -1,4 +1,5 @@
import { ref, watch } from 'vue-demi'
import { tryOnMounted } from '@vueuse/shared'
import { useEventListener } from '../useEventListener'
import type { MaybeElementRef } from '../unrefElement'
import { unrefElement } from '../unrefElement'
Expand All @@ -24,6 +25,13 @@ export interface UseElementBoundingOptions {
* @default true
*/
windowScroll?: boolean

/**
* Immediately call update on component mounted
*
* @default true
*/
immediate?: boolean
}

/**
Expand All @@ -40,6 +48,7 @@ export function useElementBounding(
reset = true,
windowResize = true,
windowScroll = true,
immediate = true,
} = options

const height = ref(0)
Expand Down Expand Up @@ -88,6 +97,11 @@ export function useElementBounding(
if (windowResize)
useEventListener('resize', update, { passive: true })

tryOnMounted(() => {
if (immediate)
update()
})

return {
height,
bottom,
Expand Down

0 comments on commit dccd1f3

Please sign in to comment.