vue vue-touch移动端手势

迈不过友情╰ 2021-07-24 12:15 801阅读 0赞
  1. 1、安装
  2. cnpm install vue-touch@next --save
  3. 2、引入
  4. main.js
  5. import VueTouch from 'vue-touch'
  6. Vue.use(VueTouch, {name: 'v-touch'}) v-touch可以是自定义名称
  7. 3、使用:
  8. Vue.use注册的name名称,默认该标签为div
  9. <v-touch
  10. (1)替换标签
  11. tag="要变成的标签名称,默认为div"
  12. (2)定义手势
  13. @事件类型='回调'
  14. (3)配置手势事件选项
  15. :小写事件类型名称-options="{ direction: 'horizontal', threshold: 100 }
  16. threshold临界值
  17. directions方向: 'up', 'down', 'left', 'right', 'horizontal', 'vertical', 'all'
  18. 具体配置查看hammerjs
  19. (4)阻止/触发手势
  20. :enabled="true/false" 允许/禁止所有的手势
  21. :enabled="{ pinch: true, rotate: false }" 允许和禁止指定手势
  22. (5)公共组件方法
  23. 1、通过ref获取到该标签
  24. 2、在方法中
  25. this.$refs.tapper.disable('tap')
  26. 公共方法:
  27. disable('手势名称')
  28. enable('手势名称')
  29. toggle('手势名称')
  30. disableAll() disable all Recognizers
  31. enableAll() enable all Recognizers
  32. isEnabled('手势名称')
  33. (6)自定义手势
  34. 在main.js中,在Vue.use之前使用
  35. VueTouchVueTouch.registerCustomEvent('doubletap', {
  36. type: '手势名称',
  37. ...手势事件的配置选项,见(3)
  38. taps: 2 对应tap手势的触发点击次数配置
  39. })
  40. > ...</v-touch>
  41. 4、事件类型:
  42. Pan平移
  43. pan, panstart, panmove, panend, pancancel,
  44. panleft, panright, panup, pandown
  45. Pinch缩放
  46. pinch, pinchstart, pinchmove,pinchend,
  47. pinchcancel, pinchin, pinchout
  48. Press按压
  49. press, pressup
  50. Rotate旋转
  51. rotate, rotatestart, rotatemove,
  52. rotateend, rotatecancel,
  53. Swipe滑动
  54. swipe, swipeleft, swiperight,
  55. swipeup, swipedown
  56. Tap点击
  57. tap

代码示例:

  1. <template>
  2. <div>
  3. category
  4. <!-- <div :class='{swipe:move}'>
  5. <v-touch @swipeleft="swipeleft" style='width:200px;height:200px;backgroundColor:red;'>Swipe me!</v-touch>
  6. 左滑
  7. </div> -->
  8. <div >
  9. <v-touch
  10. v-on:panstart="swipeleft"
  11. style='width:200px;height:200px;backgroundColor:red;'
  12. :pan-options="{ direction: 'horizontal', threshold: 100 }"
  13. v-bind:enabled="false"
  14. >Swipe me!</v-touch>
  15. 左滑2
  16. </div>
  17. <Tabbar/>
  18. </div>
  19. </template>
  20. <script>
  21. import Tabbar from '@/components/common/tabbar/tabbar.vue'
  22. export default {
  23. name:'category',
  24. data(){
  25. return{
  26. move:false
  27. }
  28. },
  29. components:{
  30. Tabbar
  31. },
  32. methods:{
  33. swipeleft()
  34. {
  35. // setTimeout(()=>{
  36. // this.$router.push('/shopcar')
  37. // },2000)
  38. this.move=true;
  39. console.log('左滑');
  40. }
  41. }
  42. }
  43. </script>
  44. <style scoped>
  45. .swipe{
  46. transform: translateX(-100%);
  47. transition: 2s;
  48. }
  49. </style>

发表评论

表情:
评论列表 (有 0 条评论,801人围观)

还没有评论,来说两句吧...

相关阅读