图片地址是从后台拿的数据,所以要动态的初始化swiper,否则loop无效
<swiper :options="swiperOption" ref="mySwiper">
<swiper-slide v-for="(item,index) in imgList" :key="index">
<img :src="item" alt />
</swiper-slide>
</swiper>
init:false很重要
swiperOption: {
init:false,
slidesPerView: 1.6,
centeredSlides: true,
// slidesOffsetBefore: 20,
// slidesOffsetAfter: 100,
spaceBetween: 10,
initialSlide: 0,
loop: true,
},
computed: {
swiper() {
return this.$refs.mySwiper.swiper;
}
},
这一步我加计时的原因是我要保证我的数据都拿到了才初始化,否则很难保证数据回来的时间 (之前我试了苹果上可以,安卓不行的时候才加上去的)
timeId = setInterval(()=>{
if(this.imgList.length===3){
this.swiper.init();
this.isShowPoster = true;
clearInterval(timeId)
}
},500)
原因的话你肯定知道 不知道的话给个链接给你看大概的原因