vue cli使用vue-touch滑动(实现左右滑动切换页面)

1原理:其实是将百度touch.js引入到项目中 然后有滑动等事件 在事件中调用方法

                    vue-touch 地址:https://github.com/vuejs/vue-touch/tree/next

2安装:

                npm install vue-touch @ next

                引入man.js(我引入的报错,找不到路径 手动改掉)

import VueTouch from 'vue-touch'

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

VueTouch.config.swipe = {

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

}

 下面是一个使用的例子 (使用提供的v-touch标签 就可以触动手势 根据不同的手势调用方法即可,swipeleft左滑事件)

<template>
    
      <div>
        <p>testRouter.vue</p>
      <v-touch v-on:swipeleft="swiperleft"  class="wrapper">left</v-touch>
      <v-touch  v-on:swiperight="swiperright" class="wrapper">right</v-touch>
   <div class="menu-container" ref="menuContainer">  
  <!-- 这个是内容 --> 
   </div>
        </div>   
</template>

<script>
 export default {
     data(){
         return{
             
         }
     },
    methods: {
    swiperleft: function () {
        console.info(111);
   this.$router.push({'path':'/b'});
  },
  swiperright: function () {
   this.$router.push({'path':'/a'});
   console.info(2222);
  }
    }
 }
</script>

<style>

</style>

    

 

转载于:https://my.oschina.net/u/3234821/blog/3036719

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值