`v-model` overrides the value of a number with trailing zeros
Vue version
3.2.41
Link to minimal reproduction
Steps to reproduce
1.Delete the data of input1
, from 1.002
to 1.00
2.Delete the data of input2
, from 1.002
to 1.00
What is expected?
After step 1 is executed. The display value of input1 is 1.00
.
After step 2 is executed, the display value of input1 and input2 are both 1.00
What is actually happening?
After step 1 is executed. input1 shows a value of 1.00
, but when step 2 is executed, input1 shows a value of 1
System Info
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Memory: 6.41 GB / 15.74 GB
Binaries:
Node: 16.16.0 - C:\Program Files\nodejs\node.EXE
npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (107.0.1418.26)
Internet Explorer: 11.0.19041.1566
Any additional comments?
No response
This is a side effect of vue rendering again and setting the input value to the new value which have the trailing zeros stripped as it's a number.
I remember we discussed this kind of formatting requires handling with a string (so any trailing zero is kept) in userland but I think this could be improved too. At the time I think we didn't cast the v-model variable to a number unless the .number
modifier was passed to v-model
This is a side effect of vue rendering again and setting the input value to the new value which have the trailing zeros stripped as it's a number.
I remember we discussed this kind of formatting requires handling with a string (so any trailing zero is kept) in userland but I think this could be improved too. At the time I think we didn't cast the v-model variable to a number unless the
.number
modifier was passed to v-model
Then can we add some judgment conditions to solve this problem, like the pr I put forward