Swiper.js如何在React.js中检测活动索引?

时间:2019-01-30 18:05:56

标签: reactjs swiper

我需要检测活动索引并将其存储。我在componentDidMount中声明了swiper,所以它只运行一次。索引变化时如何观看

private DOMSideSwiper = createRef<HTMLDivElement>()

public componentDidMount() {
const sideSwiper = new Swiper(this.DOMSideSwiper.current, {
  initialSlide: this.props.store.BuildingData.idx,
  slidesPerView: "auto",
  direction: "vertical",
  mousewheel: true,
  navigation: {
    nextEl: ".side-swiper-button-prev",
    prevEl: ".side-swiper-button-next",
  },
})
console.log(sideSwiper.activeIndex) // will display 0 
}

0 个答案:

没有答案