perf(Field): reduce input value assignment (#6489)

This commit is contained in:
neverland 2020-06-08 19:57:25 +08:00 committed by GitHub
parent 713c8e0101
commit 9adbfcb26c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -276,34 +276,26 @@ export default createComponent({
} }
let { value } = target; let { value } = target;
const { maxlength } = this; const originValue = value;
// native maxlength not work when type is number // native maxlength not work when type is number
const { maxlength } = this;
if (isDef(maxlength) && value.length > maxlength) { if (isDef(maxlength) && value.length > maxlength) {
value = value.slice(0, maxlength); value = value.slice(0, maxlength);
target.value = value;
} }
if (this.type === 'number' || this.type === 'digit') { if (this.type === 'number' || this.type === 'digit') {
const originValue = value;
const allowDot = this.type === 'number'; const allowDot = this.type === 'number';
value = formatNumber(value, allowDot); value = formatNumber(value, allowDot);
if (value !== originValue) {
target.value = value;
}
} }
if (this.formatter) { if (this.formatter) {
const originValue = value;
value = this.formatter(value); value = this.formatter(value);
}
if (value !== originValue) { if (value !== originValue) {
target.value = value; target.value = value;
} }
}
return value; return value;
}, },