import Vue from "vue";
// vue自定义指令节流
Vue.directive("throttle", {
bind: function(el, binding, vnode) {
let { delay, fn } = binding.value; //参数:时间,执行函数
delay = delay ? delay : 500;
let timer = null;
el.addEventListener("click", () => {
if(timer) return;
timer = setTimeout(()=>{
fn.apply(this,arguments);
timer = null;
},1000);
});
}
});