import type { Directive } from 'vue';

/**
 * 按钮节流指令
 */
const ThrottleDirective: Directive = {
    beforeMount(el, binding: any) {
        let throttling = false;
        el.addEventListener('click', () => {
            console.log(binding, 'binding')
            if (!throttling) {
                throttling = true;
                setTimeout(() => {
                    throttling = false;
                }, parseInt(binding.arg) || 300); // 默认节流时间为300毫秒，也可以从参数中传递
                binding.value();
            }
        });
    }
};
export default ThrottleDirective 
