From f20d60f69f4ed5ebca485ed38a73ca4030dba10a Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Fri, 13 Dec 2024 01:13:49 +0800 Subject: [PATCH] uu --- components/tpx-input/tpx-input.vue | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) 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