Appearance
v-default-img 默认图片指令
简介
图片加载失败时自动显示默认图片或自定义图片,支持头像、通用图片、URL、重试机制等。
基本用法
vue
<template>
<img v-default-img />
<img v-default-img="{ type: 'avatar' }" />
<img v-default-img="{ url: 'https://example.com/xxx.png' }" />
<img v-default-img="'https://example.com/xxx.png'" />
</template>参数说明
- 传字符串:直接作为默认图片 URL。
- 传对象:
- type: 'avatar' | 'image',内置头像/图片占位符
- url: 自定义图片 URL
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| type | 占位类型 | string | 'image' |
| url | 自定义图片地址 | string | - |
说明
- 首次加载失败会自动重试一次。
- 适用于 img 标签或包含 img 的容器。
- 内置图片地址见源码 DEFAULT_IMAGES。