Skip to main content
Vuetify0 is now in beta!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

useImage

Tracks image loading state as a reactive state machine with idle, loading, loaded, and error states.

Usage

The useImage composable owns the loading lifecycle for a single image source. Bind the returned source, onLoad, and onError to a plain image element.

vue
<script setup lang="ts">
  import { toRef } from 'vue'
  import { useImage } from '@vuetify/v0'

  const props = defineProps<{ src: string, alt: string }>()

  const { source, isLoaded, isError, onLoad, onError, retry } = useImage({
    src: toRef(() => props.src),
  })
</script>

<template>
  <img
    :alt
    :src="source"
    @load="onLoad"
    @error="onError"
  >
</template>

Architecture

Reactivity

Property/MethodReactiveNotes
statusReadonly ShallowRef of 'idle' | 'loading' | 'loaded' | 'error'
isIdle / isLoading / isLoaded / isErrorReadonly boolean refs derived from status
sourceGated srcundefined while idle, otherwise the current source
onLoad / onErrorBind to image load / error events
retryReset back to loading and re-attempt

Examples

FAQ

API Reference

The following API details are for the useImage composable.
Was this page helpful?

Ctrl+/