vue?vue-touch移動端手勢詳解
1、安裝
cnpm install vue-touch@next --save
2、引入
在main.js中
import VueTouch from 'vue-touch' Vue.use(VueTouch, {name: 'v-touch'}) ?v-touch可以是自定義名稱
3、使用
Vue.use注冊的name名稱,默認(rèn)該標(biāo)簽為div
v-touch
(1)替換標(biāo)簽
tag="要變成的標(biāo)簽名稱,默認(rèn)為div"
(2)定義手勢
@事件類型='回調(diào)'
(3)配置手勢事件選項
:小寫事件類型名稱-options="{ direction: 'horizontal', threshold: 100 }
threshold
臨界值directions
方向: 'up
', 'down
', 'left
', 'right
', 'horizontal
', 'vertical
', 'all
'- 具體配置查看
hammerjs
(4)阻止/觸發(fā)手勢
:enabled="true/false" ?
允許/禁止所有的手勢
:enabled="{ pinch: true, rotate: false }" ?
允許和禁止指定手勢
(5)公共組件方法
1、通過ref獲取到該標(biāo)簽
2、在方法中
this.$refs.tapper.disable('tap')
公共方法
disable
('手勢名稱')enable
('手勢名稱')toggle
('手勢名稱')disableAll()
disable all RecognizersenableAll()
enable all RecognizersisEnabled
('手勢名稱')
(6)自定義手勢
在main.js中,在Vue.use之前使用
VueTouchVueTouch.registerCustomEvent('doubletap', { ? type: '手勢名稱', ? ...手勢事件的配置選項,見(3) ? taps: 2 ?對應(yīng)tap手勢的觸發(fā)點擊次數(shù)配置 }) > ...</v-touch>
4、事件類型
Pan平移
pan
panstart
panmove
panend
pancancel
panleft
panright
panup
pandown
Pinch縮放
pinch
pinchstart
pinchmove
pinchend
pinchcancel
pinchin
pinchout
Press按壓
press
pressup
Rotate旋轉(zhuǎn)
rotate
rotatestart
rotatemove
rotateend
rotatecancel
Swipe滑動
swipe
swipeleft
swiperight
swipeup
swipedown
Tap點擊
tap
代碼示例
<template> ? ?<div> ? ? ?category ? ? ?<!-- <div ?:class='{swipe:move}'> ? ? ? ?<v-touch @swipeleft="swipeleft" style='width:200px;height:200px;backgroundColor:red;'>Swipe me!</v-touch> ? ? ? ?左滑 ? ? ?</div> --> ? ? ? <div > ? ? ? ?<v-touch ? ? ? ? v-on:panstart="swipeleft" ? ? ? ? style='width:200px;height:200px;backgroundColor:red;' ? ? ? ? :pan-options="{ direction: 'horizontal', threshold: 100 }" ? ? ? ? v-bind:enabled="false" ? ? ? ? >Swipe me!</v-touch> ? ? ? ?左滑2 ? ? ?</div> ? ? ?<Tabbar/> ? ?</div> </template>
<script> import Tabbar from '@/components/common/tabbar/tabbar.vue' export default { ? name:'category', ? data(){ ? ? return{ ? ? ? move:false ? ? } ? }, ? components:{ ? ? Tabbar ? }, ? methods:{ ? ? swipeleft() ? ? { ? ? ? // setTimeout(()=>{ ? ? ? // ? this.$router.push('/shopcar') ? ? ? // },2000) ? ? ?? ? ? ? this.move=true; ? ? ? console.log('左滑'); ? ? } ? } } </script>
<style scoped> .swipe{ ? transform: translateX(-100%); ? transition: 2s; } </style>
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
在vue中created、mounted等方法使用小結(jié)
這篇文章主要介紹了在vue中created、mounted等方法使用小結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07關(guān)于element中對el-input 自定義驗證規(guī)則
這篇文章主要介紹了關(guān)于element中對el-input 自定義驗證規(guī)則,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08淺談一下Vue生命周期中mounted和created的區(qū)別
每一個vue實例從創(chuàng)建到銷毀的過程,就是這個vue實例的生命周期,在這個過程中,他經(jīng)歷了從開始創(chuàng)建、初始化數(shù)據(jù)、編譯模板、掛載Dom、渲染→更新→渲染、卸載等一系列過程,那么這些過程中,具體vue做了些啥,我們今天來了解一下2023-05-05