话不多说还在赶项目,效果如下图:
只需安装 swiper 即可,不需要安装:vue-awesome-swiper
npm install swiper --save-dev
下面是完整代码:
<template>
<div class="swiper_all">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"></div>
<div class="swiper-slide"></div>
<div class="swiper-slide"></div>
</div>
</div>
</div>
</template>
<script>
import Swiper from 'swiper/swiper-bundle.min.js'
import 'swiper/swiper-bundle.min.css'
export default {
data(){
return {
}
},
mounted() {
new Swiper(".swiper-container", {
loop: true, // 循环模式选项
loopedSlides: 3, // 必设不然最后一张右边没元素
//自动播放
autoplay:{
delay:2000,
disableOnInteraction:false
},
});
}
}
</script>
<style lang="scss" scoped>
.swiper_all{overflow: hidden;
.swiper-container { overflow: visible!important; width: 80%; height: 210px;
.swiper-wrapper{
.swiper-slide{border-radius: 10px;background: red;}
.swiper-slide-active{margin-right: 10px;margin-left: 10px;}
.swiper-slide-prev{margin: 0 0 0 -10px;} /*由于swiper-slide-active左右设置了10像素,默认往右边挤过去了单独给前一个div设置负10像素左右才能对齐*/
}
}
}
</style>