import Vue from 'vue' Vue.directive('num', function (el, binding) { const min = binding.value.min const max = binding.value.max const _input = el _input.onkeyup = function (e) { let value = e.currentTarget.firstElementChild.value if (value.length == 1) { value = value.replace(/[^1-9]/g, '') } else { value = value.replace(/[^\d]/g, '') } if (min) { if (value < min) { value = min } } if (max) { if (value > max) { value = max } } e.currentTarget.firstElementChild.value = value } })