import Vue from 'vue'

//input 限制输入正整数
//v-toInt
Vue.directive('toInt', {
    // 指令的定义
    inserted: function(el, binding, vnode) {
        el.addEventListener("input", function() {
            //进行验证
            checkedfun(el);
        });
        function checkedfun(el) {
            let reg = new RegExp("^[0-9]*$");
            if (!reg.test(el.value)) {
                el.value = el.value.replace(/[^0-9]+/g, "");
                el.dispatchEvent(new Event("input"));//调用input事件使vue v-model绑定更新
            }
        }
    }
})
