uni-app-双击事件模拟
uniapp双击事件模拟<button type="default" @click="dblclick()" class="x-pf">我是双击事件</button>data(){return {time: []}}dblclick(e) {if (this.time.length < 2) {...
·
思路:设置一个变量数组,点击后对数组进行追加时间戳,够两个就清空,判断两次时间戳的差距是否在规定的事件呢
vue2
template中
<button @click="dblclick()">我是双击事件</button>
data中
time: []
methods中
dblclick(e) {
if (this.time.length < 2) {
this.time.push(new Date().getTime())
if (this.time[this.time.length - 1] - this.time[0] < 500) {//配置多晒秒内为双击
if (this.time[this.time.length - 1] - this.time[0] == 0) {
console.log('奇数点击')
} else {
console.log('0.5s内点击')
this.time = []
}
} else {
console.log('0.5s外点击')
this.time = []
}
} else {
this.time = []
}
console.log(this.time)
},
总结
更多推荐
已为社区贡献2条内容
所有评论(0)