1.0.29 • Published 1 year ago

react-dczs-image-preview v1.0.29

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-image-preview

  • 基于 react17.x 开发的预览图片组件
  • 支持 放大、缩小、复原、下载、打印、旋转、拖拽等功能
  • 支持 png、jpg、jpge、bmp、gif 等常见图片格式
  • 支持查看多个图片
  • 开箱即用 只需传图片数据 轻便简单

安装使用说明

npm i react-dczs-image-preview

// 引入组件和样式
import { reactImagePreview } from 'react-dczs-image-preview'
import 'react-dczs-image-preview/lib/style.css'

例1:
var imgData = 'xxx'
export default class App extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      showBox: true
    }
  }
  close = () => {
    this.setState({
      showBox: false
    })
  }
  open = () => {
    this.setState({
      showBox: true
    })
  }
  render() {
    return (
      <div>
        <button onClick={this.open}>open</button>
        <reactImagePreview
          showBox={this.state.showBox}
          imgData={imgData}
          close={this.close}
        />
      </div>
    )
  }
}

api

属性

属性值类型描述默认值
imgDatastring图片地址(url)-
imgArrArray图片地址(数组)-
showBoxBoolean控制图片预览器显隐false
customActionObject自定义操作栏null
isHintBoolean是否展示提示(第一张或最后一张)true
ifWaveBoolean是否点击波纹特效false
isAnimationBoolean是否动画特效false

customAction

属性值类型描述默认值
lastCardBoolean是否需要上一张true
narrowBoolean是否需要缩小true
reductionBoolean是否需要复原true
enlargeBoolean是否需要放大true
leftRotateBoolean是否需要逆时针旋转true
rightRotateBoolean是否需要顺时针旋转true
downloadFileBoolean是否需要下载true
publishBoolean是否需要打印true
nextCardBoolean是否需要下一张true
mouseWheelBoolean是否需要滚轮缩放true
mouseDownBoolean是否需要拖拽功能true

事件

事件名说明回调参数
close关闭回调-

注意

  • 若引用图片地址,相对地址使用 require()包裹或使用绝对地址
  • 若 imgData 和 imgArr 同时传了 则只有 imgData 生效
  • 不支持 base64
1.0.29

1 year ago

1.0.28

1 year ago