uniapp长按与点击冲突处理

定义两个时间戳,判断两个时间戳的相差时间来确定是长按还是点击执行不同的逻辑处理


	<template>
		<view @tap="btnClick" @longtap="btnLongTap" @touchstart='touchstart' @touchend='touchend'>测试</view>
	</template>

	<script>
		export default {
			data() {
				return {
					touchT: '',
					touchE: "",
				}
			},
			methods:{
			    btnLongTap(){
			          console.log('长按')
			    },
			    touchstart(){
			        this.touchT = new Date().getTime();
			    },
			    touchend(){
			        this.touchE = new Date().getTime();
			    },
			    btnClick(){
			        if(this.touchE-this.touchT<350){
			              console.log('点击')
			          }
			    },
			}
		}
	</script>

你可能感兴趣的:(uni-app,前端,javascript)