依赖下载:
npm i swiper
main.ts引入样式:
import ‘swiper/swiper-bundle.css’
使用:
<swiper
:modules="modules"
:slides-per-view="3"
:space-between="0"
navigation
:scrollbar="{ draggable: true }"
:observer="true"
:observeParents="true"
:autoplay="{
delay: 1000,
pauseOnMouseEnter: true,
disableOnInteraction: false
}"
>
<swiper-slide v-for="(item, index) in data" :key="index">
<div class="service-centre-item">
<div>{{ item.name }}</div>
<div>
<span>{{ item.data }}</span>
<span>{{ getUnit(item.name) }}</span>
</div>
</div>
</swiper-slide>
</swiper>
<script setup lang='ts'>
import { Swiper, SwiperSlide } from 'swiper/vue';
import { Navigation, Scrollbar, Autoplay } from 'swiper';
const modules: any = ref([Navigation, Scrollbar, Autoplay])
</script>
<style scoped lang='less'>
.swiper{
--swiper-theme-color: @sub-color;/* 设置Swiper风格 */
--swiper-navigation-color: @sub-color;/* 单独设置按钮颜色 */
--swiper-navigation-size: 14px;/* 设置按钮大小 */
:deep(.swiper-scrollbar-horizontal) {
background: transparent;
}
:deep(.swiper-scrollbar-drag) {
background: #ececec;
}
padding-bottom: 14px;
}
</style>
版权声明:本文为m0_51499501原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。