Vue中 用vue-awesome-swiper开发轮播图

https://github.com/surmon-china/vue-awesome-swiper

安装 用  

npm install vue-awesome-swiper@2.6.7 --save //比较稳定

效果图:

<template>
  <!--加这个 div用来解决 3g网下 图片显示慢时 先出现文字 占据图片位置的情况-->
  <div class="swiper">
  <swiper :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback">
    <swiper-slide v-for="item of swiperList"  :key="item.id">
      <img  class="swiper-img" src= "item.imgUrl"  height="300"
                              width="534"/>
    </swiper-slide>

    <div class="swiper-pagination"  slot="pagination"></div>
       <!--图片上那三个小点是个组件在 slot="pagination" 里   这个组件会把值传给 <Div>class=swiper 这个组件 在让他显示 因为这个swiper里面没有-->
    <!-- 出现 .swiper-pagination-bullet-active这个类名所以 <Div>class=swiper 不会显示他的样式 因为有 scoped 所以要穿透 -->
  </swiper>
  </div>
</template>

<script>
export default {
  name: 'HmoeSwiper',
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true // 让图片左滑还是右滑一直循环
      },
      swiperList: [{
        id: '0001',
        imgUrl: '~@/assets/styles/imgs/u=1754831672,534515590&fm=26&gp=0.jpg'
      }, {
        id: '0002',
        imgUrl: '../../../assets/styles/imgs/u=1810549082,3210007081&fm=26&gp=0.jpg'
      }]
    }
  }

}
</script>
<style lang="stylus" scoped>
  //    <!--图片上那三个小点是个组件在 slot="pagination" 里 如果在 .swiper下在 分一级
  //写样式将不会显示 因为定义了 scoped 所以 样式只会在 swiper组件里显示
  //  <!--图片上那三个小点是个组件在 slot="pagination" 里   这个组件会把值传给 <Div>class=swiper 这个组件 在让他显示 因为这个swiper里面没有-->
 // <!-- 出现 .swiper-pagination-bullet-active这个类名所以 <Div>class=swiper 不会显示他的样式 因为有 scoped 所以要穿透 -->

    .wrapper >>>.swiper-pagination-bullet-active //轮播图中的那个显示页数的小圆点
       background : #fff
   .swiper //  加这个 div用来解决 3g网下 图片显示慢时 先出现文字 占据图片位置的情况
     overflow:hidden //overflow 属性规定当内容溢出元素框时发生的事情。
     width: 100%
     height:0
     padding-bottom :50% //长:款的比例
     background :#eee //使图片没显示的时候 图片存在的区域显示为 灰色
     .swiper-img
         width:100%   //设置图片尺寸正好占据整个轮播图

</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值