如何修改Ant Design Image组件预览功能操作栏的图标?
Ant Design Image 组件预览自定义图标解决方案
preview.icons 属性为对象类型,而非你代码中写的数组类型,对象的键对应预览工具栏的各个操作按钮,值传入自定义图标组件即可。
支持自定义的按钮映射键
- rotateLeft:向左旋转操作按钮
- rotateRight:向右旋转操作按钮
- zoomIn:放大操作按钮
- zoomOut:缩小操作按钮
- fullscreen:全屏查看操作按钮
- close:关闭预览操作按钮
完整代码示例
// 先导入你需要用到的图标,也可以替换为自己封装的自定义图标组件 import { RotateLeftOutlined, RotateRightOutlined, ZoomInOutlined, ZoomOutOutlined, FullscreenOutlined, CloseOutlined } from '@ant-design/icons'; import { Image } from 'antd'; // 组件内使用 <Image src={imageUrl} preview={{ visible: state.visible, onVisibleChange: (visible) => closeModal(), destroyOnClose: true, icons: { rotateLeft: <RotateLeftOutlined />, rotateRight: <RotateRightOutlined />, zoomIn: <ZoomInOutlined />, zoomOut: <ZoomOutOutlined />, fullscreen: <FullscreenOutlined />, close: <CloseOutlined /> // 不需要的按钮直接给对应键赋值为null即可隐藏 } }} />
内容的提问来源于stack exchange,提问作者Rohan Keskar18
相关产品推荐
相关产品推荐

