swiper在loop模式下当前的索引值不正确情况

1、swiper在loop为false的情况下
需要获取当前的索引值:

this.active = this.activeIndex

2、swiper在loop为true的情况下
this.active = $('.swiper-slide-active').attr('data-swiper-slide-index')

或:
this.active = this.realIndex

【swiper在loop模式下当前的索引值不正确情况】3html结构:

4、data数据结构:
active: 0, swiperOption: { slidesPerView: 1, spaceBetween: 20, initialSlide: 0, loop: true, pagination: { el: '.swiper-pagination', clickable: true }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }, on: { slideChangeTransitionEnd() { this.active = $('.swiper-slide-active').attr('data-swiper-slide-index') console.log('loop:false模式:', this.activeIndex) console.log('loop:true模式1:', this.active) console.log('loop:true模式2:', this.realIndex) } } },

    推荐阅读