一、图片查看器viewer

2019-07-16  本文已影响0人  懒羊羊3号

官网
案例
接口

示例

import React from 'react';
import Viewer from 'viewerjs';
import 'viewerjs/dist/viewer.css';
import './index.less';

let viewer = '';
class ImageView extends React.PureComponent {
  componentDidMount() {
    const { id } = this.props;
    if (id) {
      viewer = new Viewer(document.getElementById(id), {
        url: 'data-original',
        toolbar: {
          zoomOut: true,
          reset: true,
          zoomIn: true,
        },
      });
    }
  }

  componentWillUnmount() {
    if (viewer) {
      viewer.destroy();
    }
  }

  render() {
    const { src, id } = this.props;
    return (
      <div>
        <img id={id} src={src} alt="Picture" className="ImageView" />
      </div>
    );
  }
}

export default ImageView;
上一篇下一篇

猜你喜欢

热点阅读