useImage
在浏览器中响应式加载图片,你可以等待结果显示它或显示后备。
¥Reactive load an image in the browser, you can wait the result to display it or show a fallback.
示例
Loading...
用法
¥Usage
vue
<script setup>
import { useImage } from '@vueuse/core'
const avatarUrl = 'https://place.dog/300/200'
const { isLoading } = useImage({ src: avatarUrl })
</script>
<template>
<span v-if="isLoading">Loading</span>
<img v-else :src="avatarUrl">
</template>
组件用法
¥Component Usage
vue
<template>
<UseImage src="https://place.dog/300/200">
<template #loading>
Loading..
</template>
<template #error>
Failed
</template>
</UseImage>
</template>