question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swipper contoller thumb in loop ( async )

See original GitHub issue

i have template

<swiper :options="swiperOptionTop" class="gallery-top" ref="swiperTop">
                <swiper-slide v-for="(slide,index) in swiperSlides" :key="index" :class="'slide-' + slide.id">
                  <img alt="" :src="slide.img">
                </swiper-slide>
               <div class="swiper-button-next swiper-button-white" slot="button-next"></div>
               <div class="swiper-button-prev swiper-button-white" slot="button-prev"></div>
             </swiper>
             <!-- swiper2 Thumbs -->
             <swiper :options="swiperOptionThumbs" class="gallery-thumbs" ref="swiperThumbs">
               <swiper-slide v-for="(slide,index) in swiperSlides" :key="index" :class="'slide-' + slide.id">
                 <img alt="" :src="slide.img">
               </swiper-slide>
             </swiper>

and script

  data () {
    return {
      swiperOptionTop: {
        spaceBetween: 10,
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      },
      swiperOptionThumbs: {
        spaceBetween: 10,
        centeredSlides: false,
        slidesPerView: 'auto',
        touchRatio: 0.2,
        slideToClickedSlide: true
      },
      swiperSlides: [
        {id: 1, img: '/static/images/products/product_01.jpg'},
        {id: 2, img: '/static/images/products/product_02.jpg'},
        {id: 3, img: '/static/images/products/product_03.jpg'}
      ],
      swiperSlidesThumb: [
        {id: 1, img: '/static/images/products/product_01.jpg'},
        {id: 2, img: '/static/images/products/product_02.jpg'},
        {id: 3, img: '/static/images/products/product_03.jpg'}
      ]
    }
  },
  mounted () {
    this.$nextTick(() => {
      const swiperTop = this.$refs.swiperTop.swiper
      const swiperThumbs = this.$refs.swiperThumbs.swiper
      swiperTop.controller.control = swiperThumbs
      swiperThumbs.controller.control = swiperTop
    })
  }

the thumbnail not controller main slider.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:21

github_iconTop GitHub Comments

12reactions
voltanecommented, Oct 30, 2020

I can confirm its not working. controller does not exist on $swiper. Adding it manually also does not work. Trying fallback to solution from swiper below v4, and using params.control also does not work. I’m using latest versions:

  • “vue-awesome-swiper”: “4.1.1”
  • “swiper”: “6.3.4”

My temporary workaround is to use slideChange event on thumbnail instance like this: @slideChange="onThumbnailChange"

where onThumbnailChange function looks like this:

onThumbnailChange(val) {
    this.$refs.swiperTop.$swiper.slideTo(val.activeIndex)
},

I’m using activeIndex instead of realIndex because in my case i set loop parameter to true (for reason why, check note here: https://swiperjs.com/api/#events and search for mySwiper.activeIndex).

In my case it works fine. Hope it helps till proper fix.

6reactions
thomaslecoeurcommented, Jul 31, 2020

A bit late, but the solution for you guys is here 👍

To access the Swiper instance, donc forget the $ before swiper : this.$refs.swiperTop.$swiper instead of this.$refs.swiperTop.swiper

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swipper contoller thumb in loop ( async ) - Bountysource
i have template <swiper :options="swiperOptionTop" class="gallery-top" ref="swiperTop"> <swiper-slide v-for="(slide,index) in swiperSlides" ...
Read more >
Swiper.js control two instances with different option loop
But i want my slider is loop=true and my thumb is loop=false . Here is my setting var galleryTop = new Swiper('.gallery-top', ...
Read more >
Swiper API
Swiper is the most modern free mobile touch slider with hardware accelerated transitions and amazing native behavior.
Read more >
Swiper Slider vertical thumbnails - JSFiddle - Code Playground
<div class="swiper-container gallery-thumbs">. 2. <div class="swiper-wrapper">. 3. <div class="swiper-slide">1</div> ... loop: true,. 4. loopedSlides: 50,.
Read more >
Responsive and Flexible Mobile Touch Slider - Swiper
Swiper is a powerful javascript library to implement responsive, accessible, ... pagination; parallax; scrollbar; thumbs; virtual; zoom.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found