You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
694 B
31 lines
694 B
11 months ago
|
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) {}
|
||
|
})
|