問題:在vue中用vue-awesome-swiper,在data中初始化,用到swiper一個方法onTap,然后再調vue的一個函數,用到this,可是。。。
data() {
return {
baseUrl:baseUrl,
imgList:[],
this.swiperOption={
pagination: '.swiper-pagination',
direction: 'horizontal',//滑動方向:水平 垂直:vertical
slidesPerView: 1,//slider容器能夠同時顯示的slides數量
paginationClickable: true,
spaceBetween: 30,
autoplay: 3000,
loop: true,
speed: 1000,
onTap: function(swiper,event){
我要在這里用到vue的數據和方法
}
}
}
},
解決方法:
`data() {
return {
baseUrl:baseUrl,
imgList:[],
swiperOption:{},
}
},
created(){
var _this = this
_this.swiperOption={
pagination: '.swiper-pagination',
direction: 'horizontal',//滑動方向:水平 垂直:vertical
slidesPerView: 1,//slider容器能夠同時顯示的slides數量
paginationClickable: true,
spaceBetween: 30,
autoplay: 3000,
loop: true,
speed: 1000,
onTap: function(swiper,event){
var curPath = event.target.currentSrc.split(_this.baseUrl)[1];
_this.getIndex(curPath)
}
}
},`
在data里先來一個空對象,在created中再來賦值,換一個思路解決!