为了账号安全,请及时绑定邮箱和手机立即绑定

Reactjs:如何添加带有旋转图片库的下一个/上一个按钮

Reactjs:如何添加带有旋转图片库的下一个/上一个按钮

www说 2022-12-02 17:27:48
我正在创建一个图片库AliceCarousel。我在这里遇到的一个错误是在制作时next或者previous它总是回到初始图像`。它不会在下一张幻灯片上停止。我在这里做的错误和帮助或建议。请。//代码class LivingService extends React.Component {  constructor(props) {    super(props);    this.state = {      currentIndex: null,      responsive: { 1024: { items: 4 } },      services : this.props.resume,      ...props,      ItemsServices:[]    };    this.galleryItems = this.galleryItems.bind(this);  }  static propTypes = {    getService: PropTypes.func.isRequired,    resume: PropTypes.object.isRequired,    auth: PropTypes.object.isRequired,    loading: PropTypes.object.isRequired  }  UNSAFE_componentWillReceiveProps(nextProps) {    if(nextProps.resume !== this.props.resume){      var services  = this.props.resume.services;      this.setState({        ItemsServices: services      })    }  }  componentDidMount() {    this.props.getService();    }  onSlideChanged = (e) => this.setState({ currentIndex: e.brand })  slideNext = () => this.setState(prevState => ({ currentIndex: prevState.currentIndex + 1 }));  slidePrev = () => this.setState(prevState => ({ currentIndex: prevState.currentIndex - 1 }));  thumbItem = (brand, i) => <span onClick={() => this.slideTo(brand._id)}>* </span>  slideTo = (_id) => this.setState({ currentIndex: _id })  galleryItems = () => {    return this.state.ItemsServices.map((brand, i) => {      if(brand.service_name === "Office"){        return (          <div className="col-xs-12" key={brand._id} data-id={brand._id} ><img src={brand.service_image_url} /></div>        )      }          })  };   render() {    const { responsive, currentIndex } = this.state    const  items = this.galleryItems();    return(      <div>        <Grid className ="col-12 service-living-gallery-grid" >          <div className="service-gallery-headline">              Living          </div>    )  }}
查看完整描述

2 回答

?
莫回无

TA贡献1865条经验 获得超7个赞

我已经通过使用解决了这个问题owlcarousel。

请查看更多OwlCarousel 在这里,我过滤了数组并返回了响应。


render() {

    const { services, loading} = this.props.resume;

    var checkImage = services.length === 0 ? [] : services.filter((item) => item.service_name === "Kitchen")

    return(

      <div>


            <OwlCarousel className="owl-theme" loop margin={10} nav>

               {checkImage.map((item, i) => ( 

                <div className="col-xs-12 item" key={item._id} data-id={item._id} >

                  <img className="service-gallery-images" src={item.service_image_url} alt=""/>

                </div>

            ))}

            </OwlCarousel>

      </div>

    )

  }


查看完整回答
反对 回复 2022-12-02
?
眼眸繁星

TA贡献1873条经验 获得超9个赞

问题很可能是您必须在方法中使用 prevState :

像这样:

 slideNext = () => this.setState(prevState => ({ currentIndex: prevState.currentIndex + 1 }));

对你的两种方法都这样做。


查看完整回答
反对 回复 2022-12-02
  • 2 回答
  • 0 关注
  • 118 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号