思路:设置一个变量数组,点击后对数组进行追加时间戳,够两个就清空,判断两次时间戳的差距是否在规定的事件呢

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)
    },

总结 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐