Vue項(xiàng)目 --- 輪播圖插件swiper

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>

輪播控制
當(dāng)不希望自動(dòng)切換的時(shí)候

autoplay: false,

當(dāng)輪播到頭的時(shí)候,不希望接著循環(huán)播放

loop: false

具體詳細(xì)配置信息查看:http://www.swiper.com.cn

關(guān)于樣式
這里要注意,我們想覆蓋掉swiper-pagination-bullet-active原有的樣式,但是樣式并不在當(dāng)前頁,因?yàn)?code>style設(shè)置了scoped的原因,所以要用3個(gè)箭頭進(jìn)行一個(gè)穿透,就不受scoped的限制了

.wrapper >>> .swiper-pagination-bullet-active
    background: #fff
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容