先导入swiper,npm i swiper@8
安个8版本的,配置在swiper官网可查
<template>
<div class="swiper anjian_swiper">
<div class="swiper-wrapper">
<div
v-for="(item, index) in scrollData"
:key="index"
class="swiper-slide"
>
<span>{{ item.name }}</span>
<span>{{ item.caseType }}</span>
<span>{{ item.disputeType }}</span>
<span>{{ item.createDate }}</span>
</div>
</div>
</div>
</template>
<script>
//下面文件地址用官网的会出问题,自己找的全局导入的地址
import Swiper from "swiper/swiper-bundle.js";
import "swiper/swiper-bundle.css";
export default {
data() {
return {
scrollData: [],
swiper: {},
};
},
watch: {
scrollData(val) {
this.$nextTick(() => {
this.swiper.init();
});
},
},
mounted() {
this.swiper = new Swiper(".swiper", {
direction: "vertical",
loop: true,
speed: 2000,
slidesPerView: "auto",
autoplay: {
delay: 0,
loopPreventsSlide: true,
disableOnInteraction: false,
pauseOnMouseEnter: true,
},
paginationClickable: true,
init: false,
});
},
methods: {
getData(data) {
this.scrollData = data;
},
},
};
</script>
<style scoped>
.anjian_swiper {
height: calc(100% - 0.9rem);
overflow: hidden;
font-size: 0;
}
.anjian_swiper .swiper-wrapper {
transition-timing-function: linear !important;
}
.anjian_swiper .swiper-slide {
text-align: left;
height: 0.4rem;
line-height: 0.4rem;
}
.anjian_swiper .swiper-slide span {
display: inline-block;
font-size: 0.18rem;
color: rgba(255, 255, 255, 0.6);
white-space: nowrap;
}
.anjian_swiper .swiper-slide span:nth-child(1) {
width: 15%;
}
.anjian_swiper .swiper-slide span:nth-child(2) {
width: 25%;
}
.anjian_swiper .swiper-slide span:nth-child(3) {
width: 25%;
}
.anjian_swiper .swiper-slide span:nth-child(4) {
width: 35%;
}
.wraptit {
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
padding: 0 0 10px 0;
margin-bottom: 10px;
}
.wraptit span {
display: inline-block;
font-size: 0.18rem;
color: rgba(255, 255, 255, 0.6);
}
</style>