Vue移动端左右滑动效果实现方法

原文:https://www.jianshu.com/p/612cd47b966d

1. 最近得到一个新需求,需要在Vue项目的移动端页面上加上左右滑动效果,在网上查阅资料,最终锁定了vue-touch

2. 下载vue-touch (https://github.com/vuejs/vue-touch/tree/next) 注意:如果Vue是2.x 的版本的话,一定要下next分支上的。

3. 使用:

    3.1 npm install vue-touch@next --save

    3.2 在main.js 中 引入:

        import VueTouch from 'vue-touch'

        Vue.use(VueTouch, {name: 'v-touch'})

        VueTouch.config.swipe = {

             threshold: 100 //手指左右滑动距离

        }

    3.3  在左右滑动页面的父页面使用,如:

        <v-touch v-on:swipeleft="onSwipeLeft" v-on:swiperight="onSwipeRight"  tag="div">

                <router-view></router-view>

        </v-touch>

        左滑事件:swipeleft, 右滑事件:swiperight, 更多事件请查阅api

4. 注意事项:

    使用左右滑动之后,发现不能上下滑动了,这是因为vue-touch 默认禁止了用户的手势操作,注意组件上有个css属性:touch-action: none;

    把这个属性覆盖一下就好了,如: touch-action: pan-y!important; 

    参考自:https://segmentfault.com/q/1010000011932395,谢谢这位网友!

 

 

 

2楼 08.11 18:38
touch-action: pan-y!important; ios 不识别 怎么办 在ios上无法上下滑动
 赞 回复
daozun作者
08.13 10:32
posted @ 2019-10-18 13:39  鳳舞九天  阅读(8758)  评论(0编辑  收藏  举报