Bind swiper events to vuejs events#238
Conversation
51ec35e to
6ef77b7
Compare
6ef77b7 to
66eb61d
Compare
|
I tried this approach and pulled latest update but I couldn't get the onSlideChange to trigger.. <swiper :options="swiperOption3" ref="mySwiper3" @slideChange="onSlideChange"> data() {
return {
solutionItem: 0,
swiperOption: {
spaceBetween: 500,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
},
swiperOption2: {
spaceBetween: 500,
pagination: {
el: '.swiper-pagination2',
clickable: true,
},
},
swiperOption3: {
spaceBetween: 100,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
}
};
}, methods: {
toSlide(i) {
//console.log(i,this.$refs);
this.$refs.mySwiper3.swiper.slideTo(i, 400);
this.solutionItem = i;
},
activeSolutionItem(solutionItem) {
return this.solutionItem === solutionItem;
},
onSlideChange(swipeID) {
// NOTE - this first argument will always be the swiper instance.
// refer to swiper docs for additional arguments passed to different
// event callbacks http://idangero.us/swiper/api/#events.
console.log(`current slide is now ${swipeID}`);
},
}, |
|
@JohnRSim I just checked locally and am getting all of the event bindings as expected. I wonder what is different in our environments? How are you importing the vue-awesome-swiper library? Can you verify that the library includes the changed code? Search for Also, are you registering vue-awesome-swiper with vue globally, or locally to the component? |
|
I ran npm update import 'swiper/dist/css/swiper.css';
import { swiper, swiperSlide } from 'vue-awesome-swiper';
export default {
name: 'home',
components: {
swiper,
swiperSlide,
},Looking in node_modules\vue-awesome-swiper I did not find "beforeDestroy","slideChange" in my folder or within this git repo - maybe I miss searched? |
|
@JohnRSim I was able to install it with |
|
ahh - I thought it had been pulled and merged into the official release :) |
|
Update to v3.1.0 please. |
|
@surmon-china it looks like you already bumped to 3.1.0. Do I need to do anything? |
|
@rDr4g0n Thank you for your contribution, no longer need to do anything, he has worked well! |
This PR binds all documented swiper events to vuejs events. This makes it so the user does not need to bind events directly to the swiper instance using
on. Eg:Swiper's event handling always binds the swiper instance to the event callback's
thiscontext, which won't do for vuejs. This PR adds event handlers to the swiper instance which call to vue's native$emitmethod, and passes the swiper instance as the first argument. Any other arguments (depending on the event) are passed through as well.Please let me know if I need to improve something. Thanks!