[Vuejs]-Getting the current position of the slide when you swipe on VueJS?

0👍

mounted hook is called only once i.e when the component is finished mounting the DOM.

There is a callback property your have available in the config option you pass while creating a new Swipe instance. This property takes a function that will be called after every slide change

you can use this to update the swipe_active data.

mounted(){
 let element = document.getElementById('mySwipe');
 if (window.innerWidth< 550){
    window.mySwipe  = new  Swipe (element, {
      startSlide: 1,
      auto: 0,
      autoRestart: true,
      continuous: true,
      disableScroll: true,
      stopPropagation: true,
      callback: this.swipeCallback,
      transitionEnd: function(index, element) {}
    });
  }
  this.swipe_active = window.mySwipe.getPos();
},

methods: {
    swipeCallback(index, element){
        this.swipe_active = window.mySwipe.getPos();
    }

}

Leave a comment