Skip to content

Visibility Directives

Visibility directives help you manage element visibility and lazy loading.

v-lazy

Lazy load images when they enter the viewport.

Basic Usage

vue
<template>
  <img v-lazy="imageUrl" />
  <img v-lazy="{ src: imageUrl, placeholder: 'placeholder.jpg' }" />
  <div v-lazy="backgroundImageUrl"></div>
</template>

API

OptionTypeDefaultDescription
srcstring-Image source URL
placeholderstring-Placeholder image URL
errorstring-Error image URL
preloadnumber0Preload distance in pixels
attemptnumber1Number of retry attempts
onLoadFunction-Callback on successful load
onErrorFunction-Callback on load error

v-intersect

Observe element intersection with the viewport.

Basic Usage

vue
<template>
  <div v-intersect="handleIntersect">Observe me</div>
  <div v-intersect="{ onEnter: handleEnter, onLeave: handleLeave }">
    Track visibility
  </div>
</template>

<script setup>
function handleIntersect(entry, observer) {
  console.log('Intersecting:', entry.isIntersecting)
}
</script>

API

OptionTypeDefaultDescription
handlerFunction-Callback when element intersects
onEnterFunction-Callback when element enters viewport
onLeaveFunction-Callback when element leaves viewport
thresholdnumber | number[]0Threshold(s) to trigger
rootMarginstring'0px'Margin around the root
oncebooleanfalseTrigger only once

v-visible

Toggle element visibility with animation support.

Basic Usage

vue
<template>
  <div v-visible="showElement">Show/Hide</div>
  <div v-visible="{ useHidden: true, initial: false }">
    Uses visibility: hidden
  </div>
</template>

API

OptionTypeDefaultDescription
handlerFunction-Callback when visibility changes
useHiddenbooleanfalseUse visibility: hidden
initialbooleantrueInitial visibility state

v-loading

Show a loading overlay on elements.

Basic Usage

vue
<template>
  <div v-loading="isLoading">Content</div>
  <div v-loading="{ value: isLoading, text: 'Loading...', lock: true }">
    Content
  </div>
</template>

API

OptionTypeDefaultDescription
valuebooleantrueLoading state
textstring-Loading text to display
backgroundstring'rgba(255, 255, 255, 0.9)'Background color
lockbooleanfalseLock scroll while loading
spinnerstring-Custom spinner HTML

Released under the MIT License.