import Vue from "vue";

// v-debaunce: 提交以后禁用按钮一段时间，防止重复提交
Vue.directive("debounce", {
  inserted(el) {
    el.v_click = () => {
      el.classList.add("is-disabled");
      el.disabled = true;
      setTimeout(() => {
        el.disabled = false;
        el.classList.remove("is-disabled");
      }, 750);
    };
    el.addEventListener("click", el.v_click);
  },
  unbind(el) {
    el.removeEventListener("click", el.v_click);
  }
});
