场景:vue-awesome-swiper的点击事件中既要访问swiper的实例也要访问vue的实例(此时this只能访问到swiper的是对象)
解决方案: 利用闭包把vue的实例this当做参数传入点击事件参数
swiperOptionPicLunbo: {
pagination: {
el: '.swiper-pagination',
clickable: true
},
touchMoveStopPropagation: true,
loop: true,
resistanceRatio: 0,
observer: true,
observeParents: true,
autoplay: {
delay: 3000,
stopOnLastSlide: false,
disableOnInteraction: false
},
preventLinksPropagation: false,
on: {
click: (function (that) {
return function (event) {
const realIndex = this.realIndex
that.getList(that.lunboImgs[realIndex], realIndex)
}
})(this),
slideChangeTransitionEnd () {
this.slideToLoop(this.realIndex, 0, false)
}
},
}