Subscribe on changes!

`v-model` overrides the value of a number with trailing zeros

avatar
Nov 1st 2022

Vue version

3.2.41

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9kd1ugzAMhV/Fyg2bVEjJJYJKe4/ctNRsVM2PnMA0Id59DrQT66ZeOcc++Rw7k3jzvhgHFJWoQ0u9jxAwDv6gbW+8owgTEHYwQ0fOQMbWTFttW2dDBDuYEppkeCmL/V69bgrqoVDLlc9kFhGNvx4jsgKo/aG3fohlLVNjTiwSxty4M14bLVIjLSB+eWwyFiekDO53U4DlLdU0pTDPS+UOu9HVM7r6n/4Lr1a82uJr+TOJ2Il1Zbk5+uISnOWlTsmqb4WgRQVLJuV4lUlr8RGjD5WUoWvTV1xC4ehd8qmgwcbeYIHB5CdynwGJwVrsNgzJyREpJ7RnJKRnzAfrH27C8nCzmL8Bq8W0nQ==

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

https://user-images.githubusercontent.com/32354856/199236867-a24941bd-4f2e-4523-a067-3ac58994ced9.mov

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

avatar
Nov 1st 2022

@sxzz hey bro, help me to determine if it is a bug, thank you 🙏

avatar
Nov 4th 2022

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

avatar
Nov 5th 2022

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