快速点击按钮会重复多次调用接口,防止出现这样的情况

全局定义,方便调用

新建plugins.js

export default {
  install (Vue) {
    // 防重复点击(指令实现)
    Vue.directive('preventReClick', {
      inserted (el, binding) {
        el.addEventListener('click', () => {
          if (!el.disabled) {
            el.disabled = true
            setTimeout(() => {
              el.disabled = false
            }, binding.value || 3000)
          }
        })
      }
    })
  }
}

在main.js引用

按钮调用直接加v-preventReClick

<el-button type="prismary" style="width:100%;" @click="handleSubmit" v-preventReClick></el-button>

亲测可用

 

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-11-28
猜你喜欢
  • 2022-12-23
  • 2021-07-26
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案