今天回复我了吗
今天回复我了吗
  • 发布:2019-10-22 14:54
  • 更新:2022-11-16 17:55
  • 阅读:5890

请问uniapp 有双击事件的方法吗

分类:uni-app

请问uniapp 有双击事件的方法吗

2019-10-22 14:54 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com - 你可愿与我再并肩

export default {  
    data() {  
        return {  
            index: 0,  
            start_time: 0,  
            end_time: 0  
        };  
    },  
    methods: {  
        fndbClick() {  
            this.index = this.index == 0 ? 1 : this.index + 1;  
            if (this.index == 1) {  
                this.start_time = new Date().getTime();  
                setTimeout(()=>{  
                    this.index = this.start_time = this.end_time = 0;  
                },200)  
            } else if (this.index == 2) {  
                this.end_time = new Date().getTime();  
                if (this.end_time - this.start_time < 300) {  
                    uni.showToast({  
                        title: '双击了屏幕',  
                        icon: 'none'  
                    })  
                }  
                this.index = this.start_time = this.end_time = 0;  
            }  
        }  
    }  
};  
</script>
zmm2113V

zmm2113V - 热爱前端

<template>  
<view @click="G8Click">狂击</view>  
</template>  
export default {    
    data() {    
        return {    
            index: 0, //双击  
        timer: null //双击  
        };    
    },    
    methods: {    
       G8Click() {  
            this.index = this.index + 1;  
            if (this.timer) {  
                clearTimeout(this.timer);  
            }  
            this.timer = setTimeout(() => {  
                if (this.index == 1) {  
                    console.log('单击');  
                }  
                if (this.index == 2) {  
                    console.log('双击');  
                }  
                if (this.index == 3) {  
                    console.log('三击');  
                }  
                if (this.index == 4) {  
                    console.log('四击');  
                }  
                console.log(this.index + '击');  
                this.index = 0;  
            }, 200);  
        },   
    }    
};    
</script>
2***@qq.com

2***@qq.com

请问解决了吗?双击事件该怎么监听

要回复问题请先登录注册