使用directive自定义属性来完成实现长按删除功能

<style>
.tou{
100%;
height:50px;
background: #f02e34;
}
</style>
v-long-del挂载自定义事件
<div id="name" v-long-del class="tou"></div>

全局自定义事件要放在vue实例前,不然会报错,提示找不到
Vue.directive('long-del', function (el) {
var a=el;//el指控制的dom
var timeout=undefined;
a.addEventListener('touchstart',start);
a.addEventListener('touchend',end);
function start(){
timeout=setTimeout(function(){
alert('确定要删除吗?');
},2000);

}
function end(){
clearTimeout(timeout);
}
});
原文地址:https://www.cnblogs.com/qiuchuanji/p/7883291.html