uniapp 多击事件

**功能:连续点击n次弹出对话框(多击事件)**
一句话总结 就是在单击事件上加一个变量记录他的点击次数,并且每次点击间隔时间不可以大于300毫秒。
<view @click='clickss(5)'>点我5次,弹出对话框</view>

<script>
	export default {
		data() {
			return {
				num:0,
				curTime:0,
				lastTime:0,
				show:false,
		},
		methods: {
			clearData(){
				this.num=0;
				this.curTime=0;
				this.lastTime=0;
			},
			clickss(n){ //入参n 表示点击n次弹出对话框 
				this.num++;
				 if(this.num==1){ 
				    this.curTime=Math.round(new Date());
				    this.lastTime=Math.round(new Date());
				}else if(this.num==n){
					if(this.curTime-this.lastTime<300){
						//弹出对话框 this.show=true;
						this.clearData();
						return;
					}else{
					    this.clearData();
					    return;
					}
				}else{
					this.lastTime=this.curTime;
					this.curTime=Math.round(new Date() );
					if(this.curTime-this.lastTime>300){
						this.clearData();
					}
				}
			}
		}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值