Swiper
轮播组件,支持滑动。
示例
横向切换
<nut-swiper
:pagination-visible="true"
direction="horizontal"
:performanceMode="true"
ref="demo1"
@slideChangeEnd="slideChangeEnd">
<div v-for="item in dataItem" class="nut-swiper-slide"><span>page{{item.name}}</span></div>
</nut-swiper>
纵向切换
<nut-swiper
:pagination-visible="false"
:performanceMode="true"
direction="vertical">
<div class="nut-swiper-slide"><span>page 1</span></div>
<div class="nut-swiper-slide"><span>page 2</span></div>
<div class="nut-swiper-slide"><span>page 3</span></div>
</nut-swiper>
无缝切换
<nut-swiper
:pagination-visible="true"
@slideChangeEnd="slideChangeEnd"
@slideChangeStart="slideChangeStart"
direction="horizontal">
<div class="nut-swiper-slide"><span>page 1</span></div>
<div class="nut-swiper-slide"><span>page 2</span></div>
<div class="nut-swiper-slide"><span>page 3</span></div>
</nut-swiper>
循环切换
<nut-swiper
:pagination-visible="true"
:loop="true"
direction="horizontal">
<div class="nut-swiper-slide"><span>page 1</span></div>
<div class="nut-swiper-slide"><span>page 2</span></div>
<div class="nut-swiper-slide"><span>page 3</span></div>
</nut-swiper>
自动切换
<nut-swiper
:pagination-visible="false"
:autoPlay="1000"
direction="vertical">
<div class="nut-swiper-slide"><span>page 1</span></div>
<div class="nut-swiper-slide"><span>page 2</span></div>
<div class="nut-swiper-slide"><span>page 3</span></div>
</nut-swiper>
懒加载切换
<nut-swiper
:pagination-visible="false"
direction="horizontal"
id="nutSwiperLazyLoad"
:lazyLoad="true"
lazyLoadingUrl="//static.360buyimg.com/exploit/mplus/2.1.81/css/i/loading.gif"
lazyLoaderrorUrl="">
<div class="nut-swiper-slide">
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t2029/269/1342378600/94347/c088416b/56581d53Ne97b6442.jpg" class="nut-swiper-lazyload"/>
<p>牙膏牙膏吃牙膏</p>
</div>
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t5944/284/7637282290/291307/34ae9129/597ed721N4d9a0e73.jpg" class="nut-swiper-lazyload"/>
<p>纯正白砂糖,味甜</p>
</div>
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t9604/129/1427755970/357543/ba77f0be/59e071fcN4a3e077d.jpg" class="nut-swiper-lazyload"/>
<p>妙洁 保鲜袋背心型食品袋中号200只装 可提携易打结</p>
</div>
</div>
<div class="nut-swiper-slide">
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t3826/185/3277282028/320781/8fbf1015/587c2fcaNc3741a59.jpg" class="nut-swiper-lazyload"/>
<p>全棉灭菌免换洗</p>
</div>
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t6028/28/1573357626/422743/9b98f679/5934c6c9N03afe631.jpg" class="nut-swiper-lazyload"/>
<p>锁定厨房油污0</p>
</div>
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t4792/130/2443359129/122816/5f47cbd2/58ff20ecN49be8a01.jpg" class="nut-swiper-lazyload"/>
<p>训练宝宝咀嚼力</p>
</div>
</div>
<div class="nut-swiper-slide">
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t13924/18/765396019/118800/71bda7ea/5a13878fN35292d9b.jpg" class="nut-swiper-lazyload"/>
<p>得力(deli)S01黑色0.5mm经典办公按动中性笔水性笔子弹头签字笔 12支/盒</p>
</div>
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t4231/114/1373063995/311341/1feeaaad/58c1000cN5c448e8d.jpg" class="nut-swiper-lazyload"/>
<p>台湾蛋黄味糙米卷</p>
</div>
<div>
<img data-src="//img11.360buyimg.com/n3/s300x300_jfs/t2005/197/1846980340/247407/fcdbd278/56e0ceffN1d106bdb.jpg" class="nut-swiper-lazyload"/>
<p>柔韧耐用,保鲜安全</p>
</div>
</div>
</nut-swiper>
事件
export default {
data(){
return{
dataItem:null,
move:1,
}
},
methods:{
slideChangeStart:function(currentPage,el,type){
console.log(type);
},
slideChangeEnd:function(currentPage,el){
console.log(currentPage);
},
},
mounted:function(){
setTimeout(()=>{
this.dataItem=[{"name":1},{"name":2},{"name":3},{"name":4},{"name":5},{"name":6}];
this.$refs.demo1.updateSlidesBindEvent(2);
},300);
}
}
Props
参数 | 说明 | 类型 | 默认值 | 可选值 |
---|
direction | swiper滑动方向 | String | "vertical" | "vertical"/"horizontal" |
paginationVisible | 分页显示与否 | Boolean | true | true/false |
paginationClickable | 分页是否可以点击 | Boolean | true | true/false |
loop | 是否循环 | Boolean | true | true/false |
speed | 过渡动画执行时间 | Number | 500 | — |
autoPlay | 自动轮播,轮播默认是循环模式 | Boolean | 0 | — |
lazyLoad | 图片是否支持lazyload加载,默认是 不lazyload | Boolean | false | flase/true |
lazyLoadingurl | loading图片url | String | 'STATIC/loading.gif' | — |
lazyLoaderrorUrl | loading图片出错时候垫底图 | String | '' | — |
freeMode | 自由切换模式 | Boolean | false | flase/true |
initPage | 设置初始时候显示的页 | Number | 1 | — |
type | 切换的模式,单个切换,还是自由切换(自动贴合) | String | 'single' | 'single/multiple' |
Methods
方法名 | 说明 | 参数 |
---|
next | 去下一页 | — |
prev | 去上一页 | — |
setPage | 设置显示当前页码页 | pageNumber |
updateSlidesBindEvent | 如果动态更新slides,可以重新调用updateSlidesEvent 绑定事件,在异步函数赋值之后,重新绑定,绑定的方法:在nut-swiper上加一个ref="demo1",在函数中用this.$refs.demo1.updateSlidesBindEvent(pageSize) 重新绑定事件 ,pageSize 可以在更新bind后,重新设置pageSize | pageSize |
Events
事件名 | 说明 | 回调参数 |
---|
slideChangeStart | 改变页开始时回调函数 | pageNumber,el |
slideChangeEnd | 改变页时回调函数 | pageNumber,el |
slideRevertStart | 拖动没有改变页时开始时回调函数 | pageNumber,el |
slideRevertEnd | 拖动没有改变页结束时回调函数 | pageNumber,el |
slideMove | 拖动过程中的回调函数 | offset,el |