如何更新vue-awesome-swiper设置(“ slidesPerView”),我已经使用过update()函数,但它似乎不起作用。
因此,swiper为ref =“ swiperPortfolio”并具有=“ swiperOption”选项, 然后,如果route = Portfoliodetail,我想更改swiper选项。但是使用update()方法不起作用
<swiper ref="swiperPortfolio" :options="swiperOption">
<swiper-slide>
</swiper-slide>
</swiper>
data() {
return {
swiperOption: {
loop:true,
slidesPerView: 2,
spaceBetween: 30,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
}
}
},
watch: {
'$route' () {
if (this.$route.name == 'UserPortfolioDetail') {
this.swiperOption.slidesPerView= 1;
this.$refs.swiperPortfolio.update();
}
else {
this.swiperOption.spaceBetween = 2;
this.$refs.swiperPortfolio.update();
}
}
},