Vue-awesome-swiper: Multiple swipers for SSR

Created on 14 Mar 2018  路  9Comments  路  Source: surmon-china/vue-awesome-swiper

Hello and thank you for this great library!

I am trying to render multiple swipers on my site. I found your demo regarding multiple swipers, but unfortunately, it's a SPA example.

Is there a way to render multiple swiper instances with SSR? The only thing I found that could have helped me was this question regarding dynamic directive arguments, but as the answer suggests, it's not possible.

Thanks a lot and keep up the good work!

Multiple swipers SSR

Most helpful comment

Should be used like this
<div v-swiper:nameA="optionsA">...
<div v-swiper:nameB="optionsB">...

All 9 comments

I found a way to do this my creating a new component (let's call it MySwiper.vue) which renders 1 swiper.
Then if I need multiple swipers on the same page, I just create multiple instances of MySwiper.
It might be useful to mention this in the docs, especially on the demo example with multiple swipers.

@nop33 How did you make multiple instances? I'm using SSR via Nuxt
In the vue file importing the same component:

import carouselA from "~/components/carouselA.vue"; import carouselB from "~/components/carouselA.vue"; export default { components: { SliderchicasA, SliderchicasB } };

The component file:

<div v-swiper:mySwipper="swiperOption"> <div class="swiper-wrapper"> <div class="swiper-slide" ...

I've tried many ways, but with no result, thanks for reading.

Should be used like this
<div v-swiper:nameA="optionsA">...
<div v-swiper:nameB="optionsB">...

@nop33 , Thanks for that. I don't know how many hours you saved me! your solution worked perfectly.

Should be used like this
<div v-swiper:nameA="optionsA">...
<div v-swiper:nameB="optionsB">...

hi dongj0316!

thanks for your suggestion, I've tried but unfortunately the prev and next arrows of both swipers still do not behave independently from each other :(

do your swipers have the arrows or only pagination?

In case someone is passing here in search for a solution to conflicts with prev and next button between multiple swipers, this is what fixed it for me:

1) Add id attributes to button's divs:
<div id="button-next-relacionados" class="swiper-button-next swiper-button-white"></div>
<div id="button-next-relacionados" class="swiper-button-next swiper-button-white"></div>

2) In the swiper options object, refer to the new ids instead of swiper-button-prev and swiper-button-next classes:

swiperOption: {
        direction: 'horizontal',
        slidesPerView: 4,
        spaceBetween: 6,
        navigation: {
          nextEl: '#button-next-relacionados',
          prevEl: '#button-prev-relacionados'
        },

Read here!

Document with directive [instance name] props.

@ramigs Good job!

Was this page helpful?
0 / 5 - 0 ratings