Image
一张图片。还没加载出来,或加载失败时,可以换成 fallbackSrc。基于 Reka UI Primitive,默认是 img。
顺便一提,alt 目前没有写到元素上。
Installation
pnpm dlx @weme-ui/weme-ui add imageUsage

Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import Image from '../image.vue'
</script>
<template>
<Image
src="https://raw.githubusercontent.com/moujinet/assets/main/weme-ui/png/circle-128.png"
width="100"
loading="lazy"
class="rounded-xl"
/>
</template>Examples
Fit




Vueexamples/fit.vueExpand codeHide code
<script lang="ts" setup>
import Image from '../image.vue'
</script>
<template>
<div class="flex flex-wrap gap-3 items-end">
<Image src="https://github.com/moujinet.png" fit="none" class="bg-muted h-18 w-30" />
<Image src="https://github.com/moujinet.png" fit="contain" class="bg-muted h-18 w-30" />
<Image src="https://github.com/moujinet.png" fit="cover" class="bg-muted h-18 w-30" />
<Image src="https://github.com/moujinet.png" fit="fill" class="bg-muted h-18 w-30" />
</div>
</template>Fallback

Vueexamples/fallback.vueExpand codeHide code
<script lang="ts" setup>
import Image from '../image.vue'
</script>
<template>
<Image
src="https://example.invalid/missing.png"
fallback-src="https://i.quotev.com/b2gtjqawaaaa.jpg"
width="100"
class="rounded-xl"
/>
</template>Props
PropTypeDefault
asAsTag | Component'img'
渲染为的元素或组件(Reka UI
Primitive)AsTag | Component'img'
asChildbooleanfalse
合并到子元素上渲染
booleanfalsefit'none' | 'contain' | 'cover' | 'fill' | 'scale''contain'
图片在框里怎么放
'none' | 'contain' | 'cover' | 'fill' | 'scale''contain'
srcstring-
图片地址
string-widthstring | number-
宽度,写到元素上
string | number-
heightstring | number-
高度,写到元素上
string | number-
fallbackSrcstring-
未进入
loaded 时显示的回退图string-fallbackDelayMsnumber0
等待这么多毫秒后再显示
fallbackSrcnumber0altstring-
已声明,模板没有绑到元素上
string-loading'eager' | 'lazy'-
原生
loading'eager' | 'lazy'-
referrerPolicy'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'-
原生
referrerpolicy,同时写到预加载用的 Image 上'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'-
crossOrigin'' | 'anonymous' | 'use-credentials'-
只设置预加载
Image 的 crossOrigin,不写到渲染出的元素上'' | 'anonymous' | 'use-credentials'-
classany-
元素额外 class
any-Events
EventType
loadingStatusChangevalue: 'idle' | 'loading' | 'error' | 'loaded'
加载状态变化时
value: 'idle' | 'loading' | 'error' | 'loaded'
Slots
SlotDescription
default元素内的内容。as 为 img 时不会渲染
元素内的内容。
as 为 img 时不会渲染Accessibility
默认是原生 img。alt 没有写到元素上,辅助技术读不到替代文本。
Files
src/components/image/image.vuesrc/components/image/image.props.tssrc/components/image/image.style.ts