uniapp项目中相册功能,要能拖动换位,所以用了插件。
插件用了@touchstart @touchmove @touchend事件,后来又加了点击相册,查看大图的功能。用@click事件实现。但@touchstart和@click一起用的话,只会执行@touchstart。尝试了stop,prevent等方法都不行。
然后发现@touchstart事件只是在点击时起到一个类似稍微放大的功能,告诉用户可以拖动图片。即使把他删了对功能影响也不大。而且既能拖动换位,又能查看大图。但样式不好看。
最终,删除@touchstart, 使用@longpress继承@touchstart稍微放大的功能,并且在开头添加
//先在data定义val为false
longpress(){
if(this.val){
return
}
this.val = true
//.....放大图片的功能
}
在@touchmove开头
move(){
if(!this.val){
return
}
//.....其他代码
}
在@touchend中
this.val = false