Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useImage.md
1---2category: Browser3---45# useImage67Reactive load an image in the browser, you can wait the result to display it or show a fallback.89## Usage1011```vue12<script setup lang="ts">13import { useImage } from '@vueuse/core'1415const avatarUrl = 'https://place.dog/300/200'16const { isLoading } = useImage({ src: avatarUrl })17</script>1819<template>20<span v-if="isLoading">Loading</span>21<img v-else :src="avatarUrl">22</template>23```2425## Component Usage2627```vue28<template>29<UseImage src="https://place.dog/300/200">30<template #loading>31Loading..32</template>3334<template #error>35Failed36</template>37</UseImage>38</template>39```4041## Type Declarations4243```ts44export interface UseImageOptions {45/** Address of the resource */46src: string47/** Images to use in different situations, e.g., high-resolution displays, small monitors, etc. */48srcset?: string49/** Image sizes for different page layouts */50sizes?: string51/** Image alternative information */52alt?: string53/** Image classes */54class?: string55/** Image loading */56loading?: HTMLImageElement["loading"]57/** Image CORS settings */58crossorigin?: string59/** Referrer policy for fetch https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy */60referrerPolicy?: HTMLImageElement["referrerPolicy"]61/** Image width */62width?: HTMLImageElement["width"]63/** Image height */64height?: HTMLImageElement["height"]65/** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#decoding */66decoding?: HTMLImageElement["decoding"]67/** Provides a hint of the relative priority to use when fetching the image */68fetchPriority?: HTMLImageElement["fetchPriority"]69/** Provides a hint of the importance of the image */70ismap?: HTMLImageElement["isMap"]71/** The partial URL (starting with #) of an image map associated with the element */72usemap?: HTMLImageElement["useMap"]73}74export type UseImageReturn = UseAsyncStateReturn<75HTMLImageElement | undefined,76any[],77true78>79/**80* Reactive load an image in the browser, you can wait the result to display it or show a fallback.81*82* @see https://vueuse.org/useImage83* @param options Image attributes, as used in the <img> tag84* @param asyncStateOptions85*/86export declare function useImage<Shallow extends true>(87options: MaybeRefOrGetter<UseImageOptions>,88asyncStateOptions?: UseAsyncStateOptions<Shallow>,89): UseImageReturn90```91