vue 长按事件?

var timeOutEvent=0;//定时器

html结构:css

<div @touchstart="gtouchstart(v)" @touchmove="gtouchmove()" @touchend="gtouchend(v)"></div>
//开始按
              gtouchstart:function gtouchstart(item){ timeOutEvent = setTimeout(function(){ vm.longPress(item) },500);//这里设置定时器,定义长按500毫秒触发长按事件,时间能够本身改,我的感受500毫秒很是合适
                  return false; }, //手释放,若是在500毫秒内就释放,则取消长按事件,此时能够执行onclick应该执行的事件
              gtouchend:function gtouchend(item){ clearTimeout(timeOutEvent);//清除定时器
                  if(timeOutEvent!=0){ //这里写要执行的内容(尤如onclick事件)
 vm.goChat(item); } return false; }, //若是手指有移动,则取消全部事件,此时说明用户只是要移动而不是长按
              gtouchmove:function gtouchmove(){ clearTimeout(timeOutEvent);//清除定时器
                  timeOutEvent = 0; }, //真正长按后应该执行的内容
              longPress:function longPress(item){ timeOutEvent = 0; //执行长按要执行的内容,如弹出菜单
                  $api.css($api.dom('.Popup'), 'display:block'); }

源地址:https://www.cnblogs.com/imsomnus/p/6429074.htmlhtml

相关文章
相关标签/搜索