1 npm 安装

 npm install vue-awesome-swiper --save

2在所用的组件中引入

 import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'

3 在components中进行注册

 components:{
  swiper,
swiperSlide
},

4 在vue-cli中组件的template中进行使用

 <template>
<swiper :options="swiperOption">
<swiper-slide v-for="(item,index) in slideImages">
<a href="#" target="_blank"><img :src="item.imageUrl" /><span class="title">{{item.title}}</span></a>
</swiper-slide>
<div class="swiper-pagination swiper-pagination-bullets" slot="pagination"></div>
</swiper>
</template>

5 对轮播图的属性进行配置

 data(){
return {
swiperOption: {
autoplay: {//自动播放
delay: 2500,
disableOnInteraction: false
},
pagination: {//分页
el: '.swiper-pagination',
clickable: true,
renderBullet(index, className) {//自定义分页的按钮
return `<span class="${className} swiper-pagination-bullet-custom"></span>`
}
}
}
}
},

其中按钮的样式的css代码如下:

 .swiper-pagination-bullet-custom {
width: 9px;
height: 9px;
text-align: center;
line-height: 20px;
font-size: 12px;
color: #000;
opacity:;
border-radius:;
background: #fff;
}
.swiper-pagination-bullet-custom.swiper-pagination-bullet-active {
color: #fff;
background: #a11703;
}

这样子轮播图就可以自动轮播啦!!!

遇到的问题:

如果要实现无缝轮播,需要在swiperOption中添加如下代码

  swiperOption: {
autoplay: {
delay: 2500,
disableOnInteraction: false
},
loop:true,//环装轮播
}

同时还要在<swiper>添加v-if控制环装轮播,否则不起作用

代码如下:

 <swiper :options="swiperOption" ref="mySwiper" v-if="swiperList.length>1">
<!--用v-if控制loop环状轮播,否则不起作用-->
<swiper-slide v-for="(item,index) in swiperList"
:index="index" :key="item.index" class="swiper_box">
<div class="goodsimg">
<img :src=imgURL+item.goodsPicture alt="" />
</div>
</swiper-slide>
</swiper>

最新文章

  1. MongoDB的备份和恢复
  2. Hadoop学习记录
  3. 英雄联盟网络测速 v1.3 全服全区取延时+取服务器维护状态+机房地理位置
  4. BZOJ2888 资源运输(LCT启发式合并)
  5. 【原】iOS容易造成循环引用的三种场景,就在你我身边!
  6. 使用 SELinux 和 Smack 增强轻量级容器
  7. OpenStack三个节点icehouse-gre模式部署
  8. c#对文件进行MD5加密校验
  9. 编码问题 关于hibernate jdbc数据库连接在xml配置与在properties文件配置的差异
  10. ADO知识的运用二(Day 28)
  11. LeetCode Merge k Sorted Lists 解决报告
  12. CSS美化网页元素
  13. css居中flex
  14. gcc update in centos to 6.3 by scl
  15. Apache 修改端口号
  16. LeetCode子域名访问计数-Python3.7&lt;五&gt;
  17. Emmet快速编写代码
  18. Twitter数据挖掘:如何使用Python分析大数据 (3)
  19. nowcoder 211E - 位运算?位运算! - [二进制线段树][与或线段树]
  20. GDAL读写矢量文件——Python

热门文章

  1. C语言中常见的图形打印总结
  2. GoCN每日新闻(2019-11-01)
  3. nginx 配置ssl
  4. UDF——提取指定线上随时间变化的物理量
  5. UIAutomatorViewer、Inspector获取元素信息
  6. [BUAA软工]Alpha阶段项目展示
  7. Mac Mini 2014 更换SSD 升级SSD
  8. TOKEN验证防止CSRF攻击的原理
  9. 虚拟机 /dev/mapper/centos-root 动态扩容
  10. git push ! [rejected] master -&gt; master (non-fast-forward) error: failed to push some refs to &#39;https://github.com/Operater9/guest&#39; hint: Updates were rejected because the tip of your current bra