vue实现全部防抖

// 全局注册防抖
Vue.component("ElButton").mixin({
  data() {
    return {
      debounce: false
    }
  },
  methods: {
    //覆盖el-button的点击事件,使用的是vue2.5.2,发现为直接覆写了原方法
    handleClick(evt) {
      if (this.debounce) {
        this.$message.warning("频繁点击,请稍后再试!");
      } else {
        this.debounce = true;
        this.$emit('click', evt);
        setTimeout(() => {
          this.debounce = false;
        }, 1000);//延时时间
      }
    }
  }
})

 

posted @ 2023-03-01 17:01  启豪  阅读(102)  评论(0编辑  收藏  举报