2020-08-22 22:02:20 +08:00
|
|
|
---
|
|
|
|
category: Components
|
2022-11-09 12:28:04 +08:00
|
|
|
group: Data Display
|
2020-08-22 22:02:20 +08:00
|
|
|
title: Image
|
|
|
|
cols: 2
|
2022-11-30 20:14:41 +08:00
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*FbOCS6aFMeUAAAAAAAAAAAAADrJ8AQ/original
|
2020-08-22 22:02:20 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
Previewable image.
|
|
|
|
|
|
|
|
## When To Use
|
|
|
|
|
|
|
|
- When you need to display pictures.
|
|
|
|
- Display when loading a large image or fault tolerant handling when loading fail.
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
## Examples
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
<code src="./demo/basic.tsx">Basic Usage</code>
|
|
|
|
<code src="./demo/fallback.tsx">Fault tolerant</code>
|
|
|
|
<code src="./demo/placeholder.tsx">Progressive Loading</code>
|
|
|
|
<code src="./demo/preview-group.tsx">Multiple image preview</code>
|
|
|
|
<code src="./demo/preview-group-visible.tsx">Preview from one image</code>
|
|
|
|
<code src="./demo/previewSrc.tsx">Custom preview image</code>
|
|
|
|
<code src="./demo/controlled-preview.tsx">Controlled Preview</code>
|
|
|
|
<code src="./demo/preview-mask.tsx" debug>Custom preview mask</code>
|
|
|
|
<code src="./demo/preview-group-top-progress.tsx" debug>Top progress customization when previewing multiple images</code>
|
|
|
|
|
2020-08-22 22:02:20 +08:00
|
|
|
## API
|
|
|
|
|
|
|
|
| Property | Description | Type | Default | Version |
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
| alt | Image description | string | - | 4.6.0 |
|
|
|
|
| fallback | Load failure fault-tolerant src | string | - | 4.6.0 |
|
|
|
|
| height | Image height | string \| number | - | 4.6.0 |
|
|
|
|
| placeholder | Load placeholder, use default placeholder when set `true` | ReactNode | - | 4.6.0 |
|
2020-09-28 14:15:23 +08:00
|
|
|
| preview | preview config, disabled when `false` | boolean \| [previewType](#previewType) | true | 4.6.0 [previewType](#previewType):4.7.0 |
|
2020-08-22 22:02:20 +08:00
|
|
|
| src | Image path | string | - | 4.6.0 |
|
|
|
|
| width | Image width | string \| number | - | 4.6.0 |
|
2021-02-02 13:35:37 +08:00
|
|
|
| onError | Load failed callback | (event: Event) => void | - | 4.12.0 |
|
2022-03-19 18:44:43 +08:00
|
|
|
| rootClassName | add custom className for image root DOM and preview mode root DOM | string | - | 4.20.0 |
|
2020-08-22 22:02:20 +08:00
|
|
|
|
2020-09-28 14:15:23 +08:00
|
|
|
### previewType
|
|
|
|
|
2020-10-10 15:26:05 +08:00
|
|
|
```js
|
2020-09-28 14:15:23 +08:00
|
|
|
{
|
2020-10-10 15:26:05 +08:00
|
|
|
visible?: boolean;
|
|
|
|
onVisibleChange?: (visible, prevVisible) => void;
|
2022-04-18 11:16:23 +08:00
|
|
|
getContainer?: string | HTMLElement | (() => HTMLElement); // v4.8.0
|
|
|
|
src?: string; // v4.10.0
|
|
|
|
mask?: ReactNode; // v4.9.0
|
|
|
|
maskClassName?: string; // v4.11.0
|
|
|
|
current?: number; // v4.12.0 Only support PreviewGroup
|
|
|
|
countRender?: (current: number, total: number) => string // v4.20.0 Only support PreviewGroup
|
2022-09-24 19:51:26 +08:00
|
|
|
scaleStep?: number;
|
2020-09-28 14:15:23 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-10-21 10:33:43 +08:00
|
|
|
Other attributes [<img>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#Attributes)
|