npm install vue-awesome-swiper@2.6.7 --save
全局引人
import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper, /* { default global options } */)
创建Swiper组件
<template>
<swiper :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback">
<!-- slides -->
<swiper-slide v-for='item of swiperList' :key='item.id'>
<img class="swiper-img" :src="item.imgUrl" alt="">
</swiper-slide>
<!-- Optional controls -->
<div class="swiper-pagination" slot="pagination"></div> //小圆点
<div class="swiper-button-prev" slot="button-prev"></div> //进度条
<div class="swiper-button-next" slot="button-next"></div> //左箭头
<div class="swiper-scrollbar" slot="scrollbar"></div> //右箭头
</swiper>
</template>
<script>
export default {
name: 'HomeSwiper',
data() {
return {
swiperOption:{
pagination: '.swiper-pagination', //配置小圆点
loop: true //无线轮播
},
swiperList: [{
id: '0001',
imgUrl: ""
},{
id: '0002',
imgUrl: ""
},{
id: '0003',
imgUrl: ""
}]
}
}
}
</script>
<style lang='stylus' scoped>
.wrapper >>> .swiper-pagination-bullet-active //css属性穿透
background: #fff
.wrapper
width: 100%
height: 0
overflow: hidden
padding-bottom: 27.25% //固定图片容器的长宽比
background: #eee
.swiper-img
width :100%
</style>
网友评论