mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-17 19:00:15 +08:00
6776bb8916
* docs: update demo * chore: add script * test: fix demo test * docs: convert demos * chore: move script * test: remove react-dom import * chore: update deps * docs: update riddle js * test: fix image test * docs: fix riddle demo
45 lines
965 B
Markdown
45 lines
965 B
Markdown
---
|
|
order: 7
|
|
title:
|
|
zh-CN: 受控的预览
|
|
en-US: Controlled Preview
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
可以使预览受控。
|
|
|
|
## en-US
|
|
|
|
You can make preview controlled.
|
|
|
|
```jsx
|
|
import React, { useState } from 'react';
|
|
import { Image, Button } from 'antd';
|
|
|
|
function ImageDemo() {
|
|
const [visible, setVisible] = useState(false);
|
|
return (
|
|
<>
|
|
<Button type="primary" onClick={() => setVisible(true)}>
|
|
show image preview
|
|
</Button>
|
|
<Image
|
|
width={200}
|
|
style={{ display: 'none' }}
|
|
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/blur,r_50,s_50/quality,q_1/resize,m_mfit,h_200,w_200"
|
|
preview={{
|
|
visible,
|
|
src: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
onVisibleChange: value => {
|
|
setVisible(value);
|
|
},
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default () => <ImageDemo />;
|
|
```
|