验证不能输入中文,如输入中文后后,input框里是没有了,但是在model里还是绑定了,提交的时候就会报错
export default { inserted(el, vDir, vNode) { //按键弹起=>限制不能输入中文 el.addEventListener('keyup', event => { let e = event || window.event let val = e.target.value.replace(/[^d]/g,''); let express = vNode.data.model.expression setValueWithExpressionVue(vNode.context.$data, express, val) }) } } function setValueWithExpressionVue (currObj, expression, value) { expression = expression.split('.') expression.forEach(function (arg, i) { if (i < expression.length - 1) { currObj = currObj[arg] } else { currObj[arg] = value } }) }
inserted(el, vDir, vNode) {