Vue中设置每隔1秒才能点击事件

版权声明:转载请声明出处 https://blog.csdn.net/weixin_40890907/article/details/82459511

 方式1 设置标志位

// 点击站点名
    handleclick (name) {
      let that = this
      if (this.flag) {
        //逻辑代码
      }
      this.flag = false
      this.timerID = setTimeout(function () {
        console.log(that.flag)
        that.flag = true
      }, 1000)
    }

1. data中默认flag为true

data () {
    return {
      flag: true,
      timerID: null
    }
  }

2. 别忘了清除定时器

destroyed () {
    clearTimeout(this.timerID)
  }

 方式2  在HTML标签上设置标志位控制是否可点击

<p @click="flag && clickEvent()"></p>

Vue官网-----事件处理

猜你喜欢

转载自blog.csdn.net/weixin_40890907/article/details/82459511