vue3按钮防抖

vue3按钮防抖_第1张图片
新建防抖文件夹

import type { Directive, DirectiveBinding } from 'vue'
export const prevent: Directive = {
  mounted(button) {
    button.addEventListener('click', () => {
      if (!button.disabled) {
        button.disabled = true
        setTimeout(() => {
          button.disabled = false
        },1500)
      }
    })
  }
}

通过获取dom节点,添加disabled

你可能感兴趣的:(vue3,javascript,前端,vue.js)