import { checkNum } from "@/utils/index";
export default {
  inserted(el, binding, vnode) {
    el.addEventListener("keyup", (e) => {
      let value = e.target.value;
      if (!value) {
        return;
      }
      const { max, set = 2 } = binding.value || {};
      if (max && value > max) {
        value = max + "";
      }
      e.target.value = checkNum(value, set) || null;
      el.firstElementChild.dispatchEvent(
        new Event("input", {
          bubbles: true,
        })
      );
    });
  },
};
