美文网首页vuejsJavaScript学习笔记深究JavaScript
一个好用精简的vuejs轮播插件——vue-swiper

一个好用精简的vuejs轮播插件——vue-swiper

作者: 冰星寒水 | 来源:发表于2016-10-30 20:05 被阅读31296次

==================================
注意这个组件没有更新,只支持Vue.js 1.0版本
===================================
这个vue轮播插件只有10k大小,使用十分方便
先放官网的使用方法。

import Vue from 'vue'
import Swiper from 'vue-swiper'
new Vue({
el: 'body',
components: {Swiper},
methods: {
onSlideChangeStart (currentPage) {
console.log('onSlideChangeStart', currentPage);
},
onSlideChangeEnd (currentPage) {
console.log('onSlideChangeEnd', currentPage);
}
}
});
<swiper v-ref:swiper
        direction="horizontal"
        :mousewheel-control="true"
        :performance-mode="false"
        :pagination-visible="true"
        :pagination-clickable="true"
        :loop=“true”
        @slide-change-start="onSlideChangeStart"
        @slide-change-end="onSlideChangeEnd">
    <div>Page 1</div>
    <div>Page 2</div>
    <div>Page 3</div>
</swiper>

Api

Properties

Name Type Default Description
direction String "vertical" Could be 'horizontal' or 'vertical' (for vertical slider).
mousewheel-control Boolean true Set to true to enable navigation through slides using mouse wheel.
pagination-visible Boolean false Toggle (hide/true) pagination container visibility when click on Slider's container
pagination-clickable Boolean false If true then clicking on pagination button will cause transition to appropriate slide.
performace-mode Boolean false Disable advance effect for better performance.
loop Boolean false Set to true to enable continuous loop mode
==================== ========= ============ ===================

Methods

Method Description
next() Go next page.
prev() Go previous page.
setPage(Number) Set current page number.

Events

Name Parameters Description
slide-change-start pageNumber Fire in the beginning of animation to other slide (next or previous).
slide-change-end pageNumber Will be fired after animation to other slide (next or previous).
slide-revert-start pageNumber Fire in the beginning of animation to revert slide (no change).
slide-revert-end pageNumber Will be fired after animation to revert slide (no change).
slider-move offset Callback function, will be executed when user touch and move finger over Swiper and move it. Receives swiper instance and 'touchmove' event as an arguments.
================== ================ ============================

使用v-ref:swipe 声明后就可以在vue.js中可以使用this.$refs.swipe来调用next();prev();setPage(1);等方法
github地址

相关文章

网友评论

  • 西巴撸:我觉得你应该可以收到!!!
    冰星寒水:你运气挺好~
  • 西巴撸:请回复我! 哥们
  • 西巴撸:哥们 看到回复下 问你个问题!!!!
  • 月儿湾啊:这个通过new的组件才可以用么,我在项目中无法滑动,提示Failed to resolve directive: el
  • 般犀:这个是移动端的,要按住滑动才有效果。
  • 小伍捡大巫:请问,我这里出现了一个问题,一调用swiper他就报Maximum call stack size exceeded是怎么回事
  • yanlvji54:这个无法滑动啊
    冰星寒水:作者没有更新vue2.0的支持,现在还在用v-ref
    yanlvji54:@Creep0907 是呀,vue2.0已经用不了了么
    Creep0907:请问你是不是用vue2.0的
  • LYSEKY::+1:
    bd72226d46e6:https://github.com/zwhGithub/vue-swiper

本文标题:一个好用精简的vuejs轮播插件——vue-swiper

本文链接:https://www.haomeiwen.com/subject/tmduuttx.html