首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Reactjs -如何使用Reactjs图片库显示导入的图像

Reactjs -如何使用Reactjs图片库显示导入的图像
EN

Stack Overflow用户
提问于 2018-08-07 01:03:30
回答 1查看 66关注 0票数 1

我一直在玩react-。

我已经将它和lightbox安装在一起,当我显示在线照片时,它工作得很好。

当我尝试显示导入的图片时,它显示的不是照片,而是相框。

代码语言:javascript
复制
import React from 'react';
import Gallery from 'react-photo-gallery';
import Lightbox from 'react-images';

import thumbsup from "../../assets/images/thumbsup.png";


const photos = [
  { src: {thumbsup}, width: 4, height: 3 },
  { src: 'https://source.unsplash.com/Dm-qxdynoEc/800x799', width: 1, height: 1 },
  { src: 'https://source.unsplash.com/qDkso9nvCg0/600x799', width: 3, height: 4 }
];


export default class Sample extends React.Component {
  constructor() {
    super();
    this.state = { currentImage: 0 };
    this.closeLightbox = this.closeLightbox.bind(this);
    this.openLightbox = this.openLightbox.bind(this);
    this.gotoNext = this.gotoNext.bind(this);
    this.gotoPrevious = this.gotoPrevious.bind(this);
  }
  openLightbox(event, obj) {
    this.setState({
      currentImage: obj.index,
      lightboxIsOpen: true,
    });
  }
  closeLightbox() {
    this.setState({
      currentImage: 0,
      lightboxIsOpen: false,
    });
  }
  gotoPrevious() {
    this.setState({
      currentImage: this.state.currentImage - 1,
    });
  }
  gotoNext() {
    this.setState({
      currentImage: this.state.currentImage + 1,
    });
  }
  render() {
    return (
      <div>
        <Gallery photos={photos} onClick={this.openLightbox} />
        <Lightbox images={photos}
          onClose={this.closeLightbox}
          onClickPrev={this.gotoPrevious}
          onClickNext={this.gotoNext}
          currentImage={this.state.currentImage}
          isOpen={this.state.lightboxIsOpen}
        />
      </div>
    )
  }
}

我试图像在其他组件中一样显示它。

代码语言:javascript
复制
import thumbsup from "../../assets/images/thumbsup.png";
{ src: {thumbsup}, width: 4, height: 3 }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51712491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档