我正在使用Vue.js 2和vue-awesome-swiper。
我想在swiper onSlideChangeEnd(swiper)
onSwipe()
this.private.privateData
我认为潜在的问题是我不知道如何访问代表swiper的this
,也不知道我的App.vue
对象touchEventsTarget。
当我尝试this.private.privateData
时,我得到Uncaught TypeError: Cannot read property 'orderFilter' of undefined
这是有道理的。
我该怎么办?谢谢。
<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>
答案 0 :(得分:4)
使用闭包。
data(){
const vue = this;
return {
private: {
privateData : 'private'
},
swiperOption: {
notNextTick: true,
setWrapperSize :true,
autoHeight: true,
onSlideChangeEnd:function(){
console.log(vue.private.privateData);
vue.onSwipe()
}
}
}
},