import Vue from 'vue' const handle = (e, vNode) => { let val = e.target.value let qualifiedNum = val .replace(/[^\d.]/g, '') .replace(/^\./g, '') .replace(/\.{2,}/g, '.') .replace(/^0{2,}/g, '0') .replace('.', '$#$') .replace(/\./g, '') .replace('$#$', '.') console.log('qualifiedNum',qualifiedNum) vNode.componentInstance.$emit('input', qualifiedNum) } Vue.directive('checkNum', { bind(el, binding, vNode) { console.log('el',binding.arg) if (!el.children.length) { return } let index = binding.arg ? binding.arg : 0 el.children[index].addEventListener('keyup', e => { handle(e, vNode) }) }, unbind(el) {} })