Open WebKieth opened 6 years ago
It happens, cause after mount and initialization of mainslider with swipers init swiper-slides wasnt updated and rendered with new content. I fix it by setInterval into the mount. But this is a bad solution, cause i need to set event callbacks for elements inside slides info this setInterval function
interval = setInterval(
->
frontSlides = document.querySelectorAll(".slider__front .swiper-slide")
backSlides = document.querySelectorAll(".slider__back .swiper-slide")
if frontSlides.length > 1 && backSlides.length > 1
that.backStage.init()
that.frontStage.init()
frontSlides = document.querySelectorAll(".slider__front .swiper-slide")
frontSlides.forEach (slide, index) ->
links = slide.querySelectorAll("a.ss")
links.forEach (link, index) ->
link.addEventListener 'click', (e) ->
e.preventDefault()
that.scrollDown()
clearInterval(interval)
,20)
v-if="data.length"
to control the swiper component (if you use loop: true
)loop functionality is duplicating only DOM nodes, meaning that your duplicated slides for the loop don't have their JS code appended as well, only the rendered result.
I spent 2 days trying to figure this out, so by using the original Swiper's methods and events, I came to a semi-infinite-loop feature:
add the following to your swiper's config
loop: true, loopedSlides: 1, on: { slideChange: function () { let lastVisibleItem = this.realIndex + this.params.slidesPerView let slidesLength = this.slides.length - 2 let lastVisibleIndex = this.realIndex + this.params.slidesPerView // if swiper reaches the end of displayed items, goToNext redirects swiper to the start if (lastVisibleItem > slidesLength) { this.slideTo(1) } // if swiper wants to go before the first item, then forward swiper to the last item if (lastVisibleIndex >= this.slides.length) { this.slideTo((slidesLength - this.params.slidesPerView) + 1) } } }
The above mentioned fix didn't work for me (swiper@8.3.2), but found another workaround. Put this in the Swiper config object:
loop: true,
loopedSlides: 1,
on: {
slideChange: (swiper) => {
const index = swiper.realIndex;
const lastSlideIndex = swiper.slides.length - 3;
if (index === 0 || index === lastSlideIndex) {
swiper.update();
// for debugging:
console.log('swiper updated');
}
}
}
Vue.js version and component version
"vue": "^2.5.16", "vue-awesome-swiper": "^3.1.3"
Reproduction Link
Steps to reproduce
I get ajax json from server and try to render array of slides with loop parameter and loopedSlides property
What is Expected?
full loop cloning includes content
What is actually happening?
duplicated slides have no content inside. Thats looks very strange, I tried to init swipers after pushing a content to the props (watch callback) - and this didnt work too, haveno idea how to fix it. Code: