swiper 滑动切换

常用于一组图片或卡片轮播,当内容空间不足时,可以用走马灯的形式进行收纳,进行轮播展现。

基本用法

横向无缝切换

  1. <nut-swiper
  2. :paginationVisible="true"
  3. direction="horizontal"
  4. :swiperData="dataItem"
  5. ref="demo1"
  6. >
  7. <div v-for="(item,index) in dataItem" :key="index" class="nut-swiper-slide">
  8. <span>page{{item.name} }</span>
  9. </div>
  10. </nut-swiper>

横向切换

  1. <nut-swiper
  2. direction="horizontal"
  3. :swiperData="dataItem"
  4. :canDragging="false"
  5. :paginationVisible="true"
  6. ref="demo2"
  7. >
  8. <div v-for="(item,index) in dataItem" :key="index" class="nut-swiper-slide">
  9. <span>page{{item.name} }</span>
  10. </div>
  11. </nut-swiper>

横向循环切换

  1. <nut-swiper
  2. direction="horizontal"
  3. :loop="true"
  4. :canDragging="false"
  5. :paginationVisible="true"
  6. ref="demo3"
  7. >
  8. <div class="nut-swiper-slide gray" >
  9. <span>page 1</span>
  10. </div>
  11. <div class="nut-swiper-slide gray_1" >
  12. <span>page 2</span>
  13. </div>
  14. <div class="nut-swiper-slide gray" >
  15. <span>page 3</span>
  16. </div>
  17. <div class="nut-swiper-slide gray_1" >
  18. <span>page 4</span>
  19. </div>
  20. </nut-swiper>
  21. <br/>
  22. <nut-button @click="add">控制下翻页</nut-button>
  23. <nut-button @click="sub">控制上翻页</nut-button>

纵向自动播放

  1. <nut-swiper
  2. direction="vertical"
  3. :autoPlay="3000"
  4. ref="demo4"
  5. >
  6. <div class="nut-swiper-slide gray" >
  7. <span>page 1</span>
  8. </div>
  9. <div class="nut-swiper-slide gray_1" >
  10. <span>page 2</span>
  11. </div>
  12. <div class="nut-swiper-slide gray" >
  13. <span>page 3</span>
  14. </div>
  15. <div class="nut-swiper-slide gray_1" >
  16. <span>page 4</span>
  17. </div>
  18. </nut-swiper>

滑动懒加载图片

  1. <nut-swiper
  2. direction="horizontal"
  3. :swiperData="dataImgItem"
  4. :lazyLoad="true"
  5. :paginationVisible="true"
  6. ref="demo5"
  7. >
  8. <div v-for="(item,index) in dataImgItem" :key="index" class="nut-swiper-slide ">
  9. <img :data-src="item.imgSrc" style="max-width:100%; max-height:100%" class="nut-img-lazyload"/> 
  10. </div>
  11. </nut-swiper>
  1. export default {
  2. data() {
  3. return {
  4. dataItem: [],
  5. dataImgItem: [],
  6. newCurrentPage: 1
  7. };
  8. },
  9. mounted() {
  10. setTimeout(() => {
  11. this.dataItem = [
  12. {
  13. name: 1
  14. },
  15. {
  16. name: 2
  17. },
  18. {
  19. name: 3
  20. },
  21. {
  22. name: 4
  23. }
  24. ];
  25. this.dataImgItem = [
  26. {
  27. imgSrc: '//m.360buyimg.com/mobilecms/s750x366_jfs/t1/18629/34/3378/144318/5c263f64Ef0e2bff0/0d650e0aa2e852ee.jpg'
  28. },
  29. {
  30. imgSrc: '//m.360buyimg.com/mobilecms/s750x366_jfs/t1/26597/30/4870/174583/5c35c5d2Ed55eedc6/50e27870c25e7a82.png'
  31. },
  32. {
  33. imgSrc: '//m.360buyimg.com/mobilecms/s750x366_jfs/t1/9542/17/12873/201687/5c3c4362Ea9eb757d/60026b40a9d60d85.jpg'
  34. },
  35. {
  36. imgSrc: '//m.360buyimg.com/mobilecms/s750x366_jfs/t1/30042/36/427/82951/5c3bfdabE3faf2f66/9adca782661c988c.jpg'
  37. }
  38. ];
  39. }, 300);
  40. },
  41. methods: {
  42. slideChangeEnd(page) {
  43. console.log(page);
  44. },
  45. slideMove(page) {
  46. console.log(page);
  47. },
  48. slideChangeStart(page) {
  49. console.log(page);
  50. },
  51. add() {
  52. this.newCurrentPage = this.newCurrentPage + 1;
  53. },
  54. sub() {
  55. this.newCurrentPage = this.newCurrentPage - 1;
  56. }
  57. }
  58. };

Prop

字段说明类型默认值
direction滑动方向Stringvertical
paginationVisible是否分页显示Booleanfalse
paginationClickable分页是否可以点击Booleanfalse
loop是否循环Booleanfalse
speed过度动画执行时间Number500
canDragging是否无缝切换Booleantrue
autoPlay自动轮播,轮播默认是循环模式,直接写轮播间隔时间Number0
initPage设置初始时候显示的页Number1
lazyLoad是否懒加载图片Booleanfalse
lazyLoadUrl懒加载的默认展示图片String-
swiperData异步数据渲染slide时,必须绑定对应数组(v2.1.7以上支持)Array-
newCurrentPage当前页数控制,用于异步切换指定页数(v2.2.14以上支持)Number1

Methods

字段说明参数
next去下一页-
prev去上一页-
setPage设置当前显示第几页number

Events

字段说明回调参数
slideChangeStart页面开始切换时候pageSize,el
slideChangeEnd页面结束切换时候pageSize,el
slideRevertStart拖动页面没改变回到原先位置开始时候pageSize,el
slideRevertEnd拖动页面没有改变回到原先位置结束时候pageSize,el
slideMove拖动过程中offset,el

Swiper 滑动切换 - 图1