环境swiper7.4.1 ,vue3
先引入需要的模块,setup return 再导出到页面上
import { Swiper, SwiperSlide } from 'swiper/vue'
import { Navigation, Pagination, Autoplay } from 'swiper'
import 'swiper/css'
import 'swiper/css/pagination'
setup() {
return {
modules: [Navigation, Pagination, Autoplay]
}
},
<swiper class="swiperPop"
ref="swiper"
:modules="modules" // 引入模块
:pagination="{ clickable: true }" // 分页圆点可以点击
slides-per-view="auto" // 显示的slides数量
:space-between="32" // slide之间间距
centered-slides // slide 居中
:autoplay="true" // 自动播放
@swiper="onSwiper" // 声明swiper
>
// 轮播内容
<swiper-slide v-for="(cellModel,index) in recommendedList" :key="cellModel.goodsId" class="swiperSlideItem">
<cart-recommend ref="recommendData" :index="index" :cellModel="cellModel" />
</swiper-slide>
</swiper>
onSwiper(swiper) {
this.swiper = swiper
},
mounted:{
this.swiper.slideTo(0) // 显示第一个slide
}
自定义slide 的宽度
.swiperSlideItem{
width: 270px;
}
目前就记录这些坑!!!
以后碰到再补!!!
|