美文网首页
Vue项目 --- 轮播图插件swiper

Vue项目 --- 轮播图插件swiper

作者: V火力全开 | 来源:发表于2018-07-11 21:52 被阅读0次

swiper安装

npm install vue-awesome-swiper --save

引入

import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'

Vue.use(VueAwesomeSwiper) 

使用例子:

<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
        <!-- slides -->
        <swiper-slide v-for="item of list" :key="item.id">
          <img class="swiper-img" :src="item.imgUrl" alt="">
        </swiper-slide>
        <!-- Optional controls -->
        <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        autoplay: 3000,
        loop: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background: #fff
  .wrapper
    overflow: hidden
    width: 100%
    height: 0
    padding-bottom: 31.25%
    background: #eee
    .swiper-img
      width: 100%
</style>

轮播控制
当不希望自动切换的时候

autoplay: false,

当轮播到头的时候,不希望接着循环播放

loop: false

具体详细配置信息查看:http://www.swiper.com.cn

关于样式
这里要注意,我们想覆盖掉swiper-pagination-bullet-active原有的样式,但是样式并不在当前页,因为style设置了scoped的原因,所以要用3个箭头进行一个穿透,就不受scoped的限制了

.wrapper >>> .swiper-pagination-bullet-active
    background: #fff

相关文章

网友评论

      本文标题:Vue项目 --- 轮播图插件swiper

      本文链接:https://www.haomeiwen.com/subject/ngskpftx.html