[Vuejs]-How to set a variable that vue can read that reacts to swiper's event handlers

0๐Ÿ‘

โœ…

I found that the answer lies in binding the instance to the variable. The final code should look like this:

data() {
const self = this; // this is the line that fixes it all
return { 
  reachedEnd: false,
  swiperNavMenu: {
    on: {
      reachEnd: function(){
        self.reachedEnd=true
      }
    }
  }
 };
},

Still thanks to sugars for pointing the way.

๐Ÿ‘คArtvader

1๐Ÿ‘

Your problem is related that reachedBeginning and reachedEnd variables are not defined

...
data() {
  return {
    reachedBeginning: false,
    reachedEnd: false,
    swiperNavMenu: {
      freeMode: true,
      slidesPerView: 5.75,
      on: {
        reachBeginning: ()=> {
          this.reachedBeginning = true; 
        },
        reachEnd: ()=> {
          this.reachedEnd = true;
        }
      }
    }
  }  
},
...
๐Ÿ‘คsugars

Leave a comment