1. 最近得到一個新需求施流,需要在Vue項目的移動端頁面上加上左右滑動效果,在網(wǎng)上查閱資料突委,最終鎖定了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. 注意事項:
? ? 使用左右滑動之后膘螟,發(fā)現(xiàn)不能上下滑動了,這是因為vue-touch 默認(rèn)禁止了用戶的手勢操作碾局,注意組件上有個css屬性:touch-action: none荆残;
? ? 把這個屬性覆蓋一下就好了,如:?touch-action: pan-y!important;?
? ? 參考自:https://segmentfault.com/q/1010000011932395净当,謝謝這位網(wǎng)友内斯!