Open loveCoderJ opened 2 weeks ago
To resolve the issue where an extra digit is added to the inputNumber
component after the input loses focus when a limit on the number of digits is set, you need to ensure that the value is properly formatted according to the specified precision when the input loses focus. This can be done by modifying the blur
method to format the value correctly.
Here is the relevant part of the code with the necessary changes:
methods: {
// ... other methods
blur () {
this.focused = false;
this.$emit('on-blur');
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
this.handleFormItemChange('blur', this.currentValue);
}
// Ensure the value is formatted according to the precision
if (this.precision !== undefined && this.currentValue !== null) {
this.currentValue = Number(this.currentValue).toFixed(this.precision);
this.$emit('update:modelValue', this.currentValue);
}
},
// ... other methods
}
Additionally, ensure that the precision
property is correctly set in the InputNumber
component. According to the types/input-number.d.ts
file from ViewUIPlus, the precision
property is used to define the number of decimal places:
export declare const InputNumber: DefineComponent<{
// ... other properties
/**
* 数值精度
*/
precision?: number;
// ... other properties
}>
This change ensures that when the input loses focus, the value is formatted to the specified precision, preventing any extra digits from being added [1][2].
To continue talking to Dosu, mention @dosu.