vue-awesome-swiper 和回调函数

vue-awesome-swiper and callback functions

我正在使用 Vue.js 2 和 vue-awesome-swiper。

我想在滑动条的回调上至少做这两件事中的一件onSlideChangeEnd(swiper)

  1. 可以触发功能onSwipe()
  2. 访问this.private.privateData

我认为潜在的问题是我不知道如何访问 this,它代表的不是刷卡器,也不是对象 touchEventsTarget,而是我的 App.vue.

当我尝试执行 this.private.privateData 时,我得到了 Uncaught TypeError: Cannot read property 'orderFilter' of undefined,这是有道理的。

我该怎么办?谢谢。

App.vue

  <template>
  <swiper :options="swiperOption" ref="mySwiper">
    <!-- slides -->
    <swiper-slide>I'm Slide 1</swiper-slide>
    <swiper-slide>I'm Slide 2</swiper-slide>
  </swiper>
</template>

<script>
  export default {
    name: 'carrousel',
    data() {
      return {
        private: {
            privateData : 'private'
        },
        swiperOption: {

          notNextTick: true,
          setWrapperSize :true,
          autoHeight: true,
          onSlideChangeEnd(swiper) {

               ***** DO SOMETHING HERE *****
          },
        }
      }
    },

   methods : {
     onSwipe() {console.log('Swiped')};
   },
    computed: {
      swiper() {
        return this.$refs.mySwiper.swiper
      }
    },
    mounted() {
      console.log('this is current swiper instance object',this.swiper)

    }
  }
</script>

使用闭包。

  data(){
    const vue = this;
    return {
      private: {
        privateData : 'private'
      },
      swiperOption: {
        notNextTick: true,
        setWrapperSize :true,
        autoHeight: true,
        onSlideChangeEnd:function(){
          console.log(vue.private.privateData);
          vue.onSwipe()
        }
      }
    }
  },