Image
Intro
Enhanced img tag with multiple image fill modes, support for image lazy loading, loading hint, loading failure hint.
Install
Register component globally via app.use, refer to Component Registration for more registration ways.
Usage
Basic Usage
Fit Mode
Round
Show round image, it may not works at fit=contain and fit=scale-down.
Lazy Load
API
Props
| Attribute |
Description |
Type |
Default |
| src |
Src |
string |
- |
| fit |
Fit mode |
string |
fill |
| alt |
Alt |
string |
- |
| width |
Width |
number | string |
- |
| height |
Height |
number | string |
- |
| radius |
Border Radius |
number | string |
0 |
| round |
Whether to be round |
boolean |
false |
| lazy-load |
Whether to enable lazy load,should register Lazyload component |
boolean |
false |
| show-error |
Whether to show error placeholder |
boolean |
true |
| show-loading |
Whether to show loading placeholder |
boolean |
true |
| error-icon |
Error icon |
string |
photo-fail |
| loading-icon |
Loading icon |
string |
photo |
icon-size v3.0.11 |
Icon size |
number | string |
32px |
| icon-prefix |
Icon className prefix |
string |
van-icon |
fit optional value
| name |
desctription |
| contain |
Keep aspect ratio, fully display the long side of the image |
| cover |
Keep aspect ratio, fully display the short side of the image, cutting the long side |
| fill |
Stretch and resize image to fill the content box |
| none |
Not resize image |
| scale-down |
Take the smaller of none or contain |
Events
| Event |
Description |
Arguments |
| click |
Emitted when image is clicked |
event: MouseEvent |
| load |
Emitted when image loaded |
- |
| error |
Emitted when image load failed |
- |
Slots
| Name |
Description |
| default |
Custom the content below the image |
| loading |
Custom loading placeholder |
| error |
Custom error placeholder |
Less Variables
How to use: Custom Theme.
| Name |
Default Value |
Description |
| @image-placeholder-text-color |
@gray-6 |
- |
| @image-placeholder-font-size |
@font-size-md |
- |
| @image-placeholder-background-color |
@background-color |
- |
| @image-loading-icon-size |
32px |
- |
| @image-loading-icon-color |
@gray-4 |
- |
| @image-error-icon-size |
32px |
- |
| @image-error-icon-color |
@gray-4 |
- |