vue-awesome-swiper实现轮播图

vue-awesome-swiper实现轮播图

1.首先通过npm安装vue-awesome-swiper,我在项目中用的是2.6.7版本

    npm install vue-awesome-swiper@2.6.7 –save

2. 在main.js中引入

import VueAwesomeSwiper from 'vue-awesome-swiper'

import 'swiper/dist/css/swiper.css'

Vue.use(VueAwesomeSwiper)

3.实现轮播图

  1. <template>
  2.  <div class="wrapper">
  3.  <swiper :options="swiperOption" v-if="showSwiper" ref="mySwiper" >
  4.     <!-- slides -->
  5.     <swiper-slide v-for="item of list" :key="item.id">
  6.        <img class="swiper-img" :src="item.imgUrl"/>
  7.     </swiper-slide>
  8.     <div class="swiper-pagination" slot="pagination"></div>
  9.   </swiper>
  10.   </div>
  11. </template>
  12.  
  13. <script>
  14.     export default {
  15.         name:"HomeSwiper",
  16.         props:{
  17.           list:Array
  18.         },
  19.         data (){
  20.            return{
  21.             swiperOption:{
  22.                pagination:".swiper-pagination",
  23.                autoplay: 2000,
  24.                loop:true,
  25.                paginationClickable: true,
  26.                observer:true,
  27.                observeParents:true
  28.             }
  29.  
  30.           }
  31.         } ,
  32.          computed: {
  33.           showSwiper () {
  34.           return this.list.length
  35.         }
  36.       }
  37.     }
  38.  
  39. </script>
  40.  
  41. <style lang="stylus" scoped>
  42.   .wrapper >>> .swiper-pagination-bullet-active
  43.     background:#fff
  44.   .wrapper
  45.     overflow:hidden
  46.     width:100%
  47.     height 0
  48.     padding-bottom:31.25%
  49.     background:#eee
  50.     .swiper-img
  51.        width:100%
  52. </style>
posted on 2018-05-08 00:18 gisery 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值