VUE中如何优雅的动态绑定长按事件

时间:2022-02-19 19:29:47

答案没有:

图片是从后端传过来,

加到imgTarget属性,实现长按点击删除该图片

    let img = document.createElement('img');
img.src = "/"+res.data.errmsg.img;
img.setAttribute('click','');
img.setAttribute('ontouchstart','window.timeOutEvent=setTimeout(()=>{let con=confirm("确定要删除吗?");if(con){this.remove()}clearTimeout(timeOutEvent);},50);');
img.setAttribute('ontouchmove','clearTimeout(timeOutEvent);')
img.setAttribute('ontouchend','clearTimeout(timeOutEvent);')
_this.picture.push(img.src);
document.getElementById("imgTarget").appendChild(img);