import type { Directive } from 'vue';

/**
 * 按钮防抖指令
 */

const DebounceDirective: Directive = {
    beforeMount(el, binding) {
        let timer: any;
        el.addEventListener('click', () => {
            clearTimeout(timer);
            timer = setTimeout(() => {
                binding.value();
            }, parseInt(binding.arg) || 300); // 默认防抖时间为300毫秒，也可以从参数中传递
        });
    }
};

export default DebounceDirective;
