vue2.0使用 swiper组件完成有缝轮播; 具体效果可参照下图所示
<template>
<div class="hello">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="(i,index) in 5" :key="index">{{index}}</div>
</div>
</div>
</div>
</template>
<script>
import Swiper from 'swiper/swiper-bundle.min.js'
import 'swiper/swiper-bundle.min.css'
export default {
name: 'HelloWorld',
props: {
msg: String,
},
mounted() {
new Swiper('.swiper-container',{
slidesPerView: "auto",//每页显示数量,auto为自动填充,3为每页显示3块
centeredSlides: true,//轮播图自动居中
spaceBetween: 10,//轮播图左右之间的间距,配合css样式中的width实现效果
initialSlide: 0, //轮播图初始下标位置
})
},
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.swiper-container{
width:100%;
overflow: hidden;
height: 400px;
}
/* 每个轮播图占比大小,100%则整个屏幕铺满 */
.swiper-slide{
width: 90%;
height: 300px;
line-height: 20rem;
background: red;
border-radius: 10px;
}
/* 滑动到当前轮播图的样式 */
.swiper-slide-active{
background:#ff6600;
color:#fff;
}
</style>