vue-awesome-swiper icon indicating copy to clipboard operation
vue-awesome-swiper copied to clipboard

Navigation buttons not working

Open miller-kevin opened this issue 3 years ago • 41 comments

Vue.js version and component version

Latest from NPM (4.1.1)

Reproduction Link

I can't reproduce it when starting with the suggested fiddle link, which means it's clearly on my end, but I could use some help

This is my configuration:

<template>
<swiper class="swiper" ref="slideSwiper" 
                        :options="swiperOptions"
                        :auto-destroy="true"
                        :delete-instance-on-destroy="true"
                        :cleanup-styles-on-destroy="true">
                    <swiper-slide class="carousel-slide" v-for="(slide, i) in sliderSlides"
                                  :key="'slide ' + i">
                        <img :src="$utils.getThumbnailUrl('xs', slide, false, true)" />
                    </swiper-slide>
                    <div class="swiper-button-next" slot="button-next"></div>
                    <div class="swiper-button-prev" slot="button-prev"></div>
</swiper>
</template>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper';
import 'swiper/swiper-bundle.css';

export default {
    components: {
        Swiper,
        SwiperSlide
    },

    data() {
        return {
            swiperOptions: {
                    //loop: true,
                    //loopedSlides: 5, // looped slides should be the same
                    spaceBetween: 30,
                    centeredSlides: true,
                    slidesOffsetBefore: '100px',
                    slidesOffsetAfter: '100px',
                    slidesPerView: 'auto',
                    touchRatio: 0.2,
                    slideToClickedSlide: true,
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev'
                    }
                }
        }
    }
}

The next/previous buttons show up properly, but have no click event bound to them for some reason. What am I doing wrong?

miller-kevin avatar Jul 08 '20 16:07 miller-kevin

If relevant, this is happening in a bootstrap-vue modal

miller-kevin avatar Jul 08 '20 16:07 miller-kevin

I have the same problem.

michaellux avatar Jul 08 '20 16:07 michaellux

I have the same problem.

Does your pagination fail to show up as well? I just figured I'd skip the buttons and go with pagination, but the swiper-pagination-bullets class that gets added to the example pages automatically do not get added to my pagination at all. Somethings bugging out and I have no idea what it could be

miller-kevin avatar Jul 08 '20 17:07 miller-kevin

Does your pagination fail to show up as well? I just figured I'd skip the buttons and go with pagination, but the swiper-pagination-bullets class that gets added to the example pages automatically do not get added to my pagination at all. Somethings bugging out and I have no idea what it could be

I don't use pagination. So I can't say anything about it.

Before I installed the 'vue-awesome-swiper', I used a clean 'swiper' and navigation worked in it.

michaellux avatar Jul 08 '20 18:07 michaellux

I am having the same issue. Downgraded to an earlier version and navigation worked again.

kwalkerm avatar Jul 08 '20 20:07 kwalkerm

I am having the same issue. Downgraded to an earlier version and navigation worked again.

I'll give it a shot, which version did you downgrade to?

miller-kevin avatar Jul 08 '20 20:07 miller-kevin

I am having the same issue. Downgraded to an earlier version and navigation worked again.

You're a damn superhero. Went to 3.1.3 and it works once I sorted out all the differences in versions from my codebase

miller-kevin avatar Jul 08 '20 21:07 miller-kevin

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

sergey-seleznev avatar Jul 09 '20 06:07 sergey-seleznev

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

Thank you. I took advantage of your recommendation. It all worked out.

michaellux avatar Jul 09 '20 07:07 michaellux

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

Thanks, this worked for me, was having issues with pagination , navigation and importing style sheets as detailed in installation instructions.

jasonloeve avatar Jul 10 '20 01:07 jasonloeve

我现在使用也存在问题 还没有解决

yuanxianjun avatar Jul 10 '20 09:07 yuanxianjun

Yo utilizo "swiper": "^5.4.2", y "vue-awesome-swiper": "^4.1.1".

import Vue from 'vue' import VueAwesomeSwiper from 'vue-awesome-swiper' import 'swiper/css/swiper.css' Vue.use(VueAwesomeSwiper)

intenta eliminar tu node_modules swiper y vuelve correo npm install.

defcom20 avatar Jul 13 '20 17:07 defcom20

I'm having the same issue since using vue-awesome-swiper for the second time in a more recent project with an updated version. If you don't want to downgrade, I found a workaround. You can implement navigation through a ref on the swiper:

If you have the swiper component with a ref like so: <Swiper ref="mySwiperRef"></Swiper>

you can access the slide event like so from a method: this.$refs.mySwiperRef.$swiper.slideNext() or this.$refs.mySwiperRef.$swiper.slidePrev()

hope this helps.

MichaelMansourati avatar Jul 13 '20 22:07 MichaelMansourati

I'm having the same issue since using vue-awesome-swiper for the second time in a more recent project with an updated version. If you don't want to downgrade, I found a workaround. You can implement navigation through a ref on the swiper:

If you have the swiper component with a ref like so: <Swiper ref="mySwiperRef"></Swiper>

you can access the slide event like so from a method: this.$refs.mySwiperRef.$swiper.slideNext() or this.$refs.mySwiperRef.$swiper.slidePrev()

hope this helps.

Yeah, that's a viable fix for the navigation, but the modern version also has broken pagination. I'm not familiar with a work around for that, so I still had to downgrade

miller-kevin avatar Jul 13 '20 22:07 miller-kevin

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

You are an absolute legend, fixed every single issue i was having in Nuxt. Cannot thank you enough. Removed swiper 6, changed to this version and everything just started working again, pagination, buttons, the lot.

drinkmorewaters avatar Jul 16 '20 03:07 drinkmorewaters

I solved the problem this way Define swiper globally with this code

import Vue from 'vue' import {Swiper as SwiperClass, Pagination, Navigation, Mousewheel, Autoplay} from 'swiper/swiper.esm' import getAwesomeSwiper from 'vue-awesome-swiper/dist/exporter'

SwiperClass.use([Pagination, Mousewheel, Navigation, Autoplay]) Vue.use(getAwesomeSwiper(SwiperClass)) const {Swiper, SwiperSlide} = getAwesomeSwiper(SwiperClass)

// import style import 'swiper/swiper-bundle.min.css'

jalalianmohsen89 avatar Jul 28 '20 13:07 jalalianmohsen89

@jalalianmohsen89 awesome! Thanks for the working workaround! For those who are using swiper as a directive, here is a bit modified workaround:

<!-- You can find this swiper instance object in current component by the "mySwiper"  -->
      <div v-swiper:mySwiper="swiperOptions">

  import 'swiper/swiper-bundle.min.css'
  import LazyHydrate from 'vue-lazy-hydration'
  import {Swiper as SwiperClass, Pagination, Navigation} from 'swiper/swiper.esm.js'
  import getAwesomeSwiper from 'vue-awesome-swiper/dist/exporter'

  // Swiper modules
  SwiperClass.use([Pagination, Navigation])

  // local component
  const {directive} = getAwesomeSwiper(SwiperClass)

export default {
    directives: {
      swiper: directive
    },
// Your specific code will go here
}

Btw, such an approach also has a benefit of smaller resulting bundle size since it allows you to include only modules you actually use. I wish we could do the same incremental import of CSS together with the imported module.

AndrewBogdanovTSS avatar Jul 30 '20 13:07 AndrewBogdanovTSS

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

Swiper 5x doesn't render in ie11 and throw some syntax errors 🤯 It's either navigation works or ie depends on the version of swiper we're using :(

laksmaria avatar Aug 12 '20 14:08 laksmaria

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

Swiper 5x doesn't render in ie11 and throw some syntax errors 🤯 It's either navigation works or ie depends on the version of swiper we're using :(

Are you using Babel at all? There's a fix that involves excluding dom7 and swiper from transpilation

miller-kevin avatar Aug 12 '20 14:08 miller-kevin

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

It's better to downgrade, since this lib is outdated with swiper v6.x

I'm having the same issue since using vue-awesome-swiper for the second time in a more recent project with an updated version. If you don't want to downgrade, I found a workaround. You can implement navigation through a ref on the swiper:

If you have the swiper component with a ref like so: <Swiper ref="mySwiperRef"></Swiper>

you can access the slide event like so from a method: this.$refs.mySwiperRef.$swiper.slideNext() or this.$refs.mySwiperRef.$swiper.slidePrev()

hope this helps.

Using the workaround above will cause some issues, like the buttons not properly hiding when the centeredSlides property is set to true.

carlos-ribeiro-cedro avatar Aug 25 '20 12:08 carlos-ribeiro-cedro

@carlos-ribeiro-cedro why to downgrade if you can set it up like so? https://github.com/surmon-china/vue-awesome-swiper/issues/680#issuecomment-666364812

AndrewBogdanovTSS avatar Aug 25 '20 15:08 AndrewBogdanovTSS

@AndrewBogdanovTSS well, I guess the API documentation itself is also outdated, because if you look right to the usage of Navigation here, for example, there's no import of { Navigation } from swiper/swiper.esm.js and this example does not work. Then you have to search for it on the dependent library swiper, what for me is a bit messy. Not mentioning there's no way to use it anymore as a component, only as a directive but then you have to rebuild your entire html.

carlos-ribeiro-cedro avatar Aug 25 '20 19:08 carlos-ribeiro-cedro

Well, life isn't perfect, I agree. But I would use newest swiper features rather than to roll back to outdated version which is more than 2 years old

AndrewBogdanovTSS avatar Aug 25 '20 21:08 AndrewBogdanovTSS

There is simple and clean workaround without need to downgrade. Tested fine with [email protected] and [email protected]

<swiper ref="swiper" :options="swiperOptions">
	<div class="swiper-button-prev" slot="button-prev" @click="prev()"></div>
	<div class="swiper-button-next" slot="button-next" @click="next()"></div>
	<!-- ... -->
</swiper>
<script lang="ts">
import Vue from 'vue';

// @ts-ignore
import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper';
import 'swiper/swiper-bundle.css';

export default Vue.extend({
	components: { Swiper, SwiperSlide },
	directives: {
		swiper: directive
	},
	data: () => ({
		swiperOptions: {
			navigation: {
				nextEl: '.swiper-button-next',
				prevEl: '.swiper-button-prev'
			}
		}
	}),
	methods: {
		prev() {
			this.$refs.swiper.$swiper.slidePrev();
		},
		next() {
			this.$refs.swiper.$swiper.slideNext();
		}
	}
});
</script>

lucien144 avatar Sep 03 '20 08:09 lucien144

@lucien144 no, it's not a good solution and it was mentioned here before https://github.com/surmon-china/vue-awesome-swiper/issues/680#issuecomment-657823733

AndrewBogdanovTSS avatar Sep 03 '20 08:09 AndrewBogdanovTSS

Same problem here. This package currently works fine with Swiper v5 (i.e. yarn add [email protected] and import "swiper/css/swiper.css"). Swiper v6.0.0 and v6.0.1 seems to be not compatible so far with the broken navigation (at least).

It worked for me, thanks!

mathvalenza avatar Oct 24 '20 14:10 mathvalenza

@jalalianmohsen89 awesome! Thanks for the working workaround! For those who are using swiper as a directive, here is a bit modified workaround:

<!-- You can find this swiper instance object in current component by the "mySwiper"  -->
      <div v-swiper:mySwiper="swiperOptions">

  import 'swiper/swiper-bundle.min.css'
  import LazyHydrate from 'vue-lazy-hydration'
  import {Swiper as SwiperClass, Pagination, Navigation} from 'swiper/swiper.esm.js'
  import getAwesomeSwiper from 'vue-awesome-swiper/dist/exporter'

  // Swiper modules
  SwiperClass.use([Pagination, Navigation])

  // local component
  const {directive} = getAwesomeSwiper(SwiperClass)

export default {
    directives: {
      swiper: directive
    },
// Your specific code will go here
}

Btw, such an approach also has a benefit of smaller resulting bundle size since it allows you to include only modules you actually use. I wish we could do the same incremental import of CSS together with the imported module.

Perfect solution for now, saved my code not compiling swiper to ES5. I didn't use LazyHydrate and moved my css import to main.js, which works better in my case. I'm using Gridsome, but it's unrelated to this issue.

Much appreciated!

matiyin avatar Nov 04 '20 10:11 matiyin

Does anybody have a workaround for React? I'm having the same problem there

The Swiper 5.4.5 version also still has the Windows NPM bug https://github.com/nolimits4web/swiper/issues/3985 Greetings from Munich

Mixermachine avatar Dec 28 '20 18:12 Mixermachine

@Mixermachine we already resolved this issue for 6.x.x, I created an issue as a reminded to release a fix to 5.x.x https://github.com/nolimits4web/swiper/issues/4081
But it will happen after 11.01.21

vltansky avatar Dec 30 '20 08:12 vltansky

@vltansky Thanks for your reply, but you reference just the 3985 bug right? My initial problem is the same as this thread describes but for React (ionic to be specific).

The Navigation buttons do not work for me. I switched away from swiper because it was really not working for me.

Mixermachine avatar Jan 06 '21 13:01 Mixermachine