swiper 滑动切换请使用手机扫码体验

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

基本用法

横向无缝切换

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

横向切换

  1. html
    <nut-swiper
  2. direction="horizontal"
  3. ref="demo2"
  4. :canDragging="false"
  5. :paginationVisible="true"
  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. html
    <nut-swiper
  2. direction="horizontal"
  3. ref="demo3"
  4. :loop="true"
  5. :canDragging="false"
  6. :paginationVisible="true"
  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>

纵向自动播放

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

滑动懒加载图片

  1. html
    <nut-swiper
  2. direction="horizontal"
  3. ref="demo4"
  4. :lazyLoad="true"
  5. :paginationVisible="true"
  6. >
  7. <div v-for="(item,index) in dataImgItem" :key="index" class="nut-swiper-slide ">
  8. <img :data-src="item.imgSrc" style="max-width:100%; max-height:100%" class="nut-img-lazyload"/>
  9. </div>
  10. </nut-swiper>
  1. javascript
    export default{
  2. data(){
  3. return{
  4. dataItem:null,
  5. dataImgItem:[],
  6. }
  7. },
  8. mounted(){
  9. setTimeout(()=>{
  10. this.dataItem = [{
  11. name:1
  12. },{
  13. name:2
  14. },{
  15. name:3
  16. },{
  17. name:4
  18. }]
  19. this.dataImgItem = [
  20. {
  21. imgSrc:'//m.360buyimg.com/mobilecms/s843x843_jfs/t19441/80/1577112624/568821/1ee9b683/5ad064f1Nf41a94b4.jpg'
  22. },
  23. {
  24. imgSrc:'//m.360buyimg.com/mobilecms/s843x843_jfs/t16798/338/1617130854/542623/4c197f4d/5ad064f1Nce5f69e2.jpg'
  25. },
  26. {
  27. imgSrc:'//m.360buyimg.com/mobilecms/s843x843_jfs/t22123/348/720079801/233727/23c4c0a4/5b162d64Nc5883413.jpg'
  28. },
  29. {
  30. imgSrc:'//m.360buyimg.com/mobilecms/s843x843_jfs/t1/27233/9/354/82863/5c090a0eEe2a350d8/aaa6686ce133e364.jpg'
  31. }
  32. ];
  33. this.$refs.demo1.updateEvent(1);
  34. this.$refs.demo2.updateEvent();
  35. this.$refs.demo4.updateEvent();
  36. },300)
  37. }
  38. }

Prop

字段说明类型默认值
direction滑动方向Stringvertical
paginationVisible是否分页显示Booleanfalse
paginationClickable分页是否可以点击Booleanfalse
loop是否循环Booleanfalse
speed过度动画执行时间Number500
canDragging是否无缝切换Booleantrue
autoPlay自动轮播,轮播默认是循环模式,直接写轮播间隔时间Number0
initPage设置初始时候显示的页Number1
lazyLoad是否懒加载图片Booleanfalse
lazyLoadUrl懒加载的默认展示图片String-

Methods

字段说明参数
next去下一页-
prev去上一页-
setPage设置当前显示第几页number
updateEvent异步数据渲染slide,都需要重新调用方法,绑定事件,如【横向无缝滑动】this.$ref.demo1.update(1)。也提供设置初始页面number

Events

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