diff --git a/components/tpx-input/tpx-input.vue b/components/tpx-input/tpx-input.vue index 8f49020..0e4c324 100644 --- a/components/tpx-input/tpx-input.vue +++ b/components/tpx-input/tpx-input.vue @@ -125,13 +125,21 @@ }, formatter(val) { let newVal = val - if(this._digit) { - let reg = new RegExp(`^\\d*(\\.?\\d{0,${this._digit}})`, 'g') - newVal = val.match(reg)[0] - } - if(typeof this._maxNum != 'undefined') { - if(val > this._maxNum) { - newVal = this._maxNum + if((this.type == 'number' || this._digit || this._maxNum) && (typeof val == 'string' && val)) { + newVal = Number(val) // 需要格式化输入框的格式 + // 判断是否输入了数字 + if(!isNaN(newVal)) { + if(this._digit) { + let reg = new RegExp(`^\\d*(\\.?\\d{0,${this._digit}})`, 'g') + newVal = val.match(reg)[0] + } + if(typeof this._maxNum != 'undefined') { + if(newVal > Number(this._maxNum)) { + newVal = this._maxNum + } + } + } else { + newVal = '' } } return newVal