v-model.trim not removing whitespaces
Version
3.2.31
Reproduction link
Steps to reproduce
- See the SFC Playground link
- When using v-model.trim on an input, the whitespaces in the message are not removed
- (Additional info: More the one whitespaces are removed from the template, but this also happens if I'm not using .trim at all)
What is expected?
Input: Hello how are you? Trimmed message: Hellohowareyou?
What is actually happening?
Input: Hello how are you? Trimmed message: Hello how are you?
Triming means "remove leading and trailing white spaces". It does not mean "remove any whitespace found in this string".
@LinusBorg Thank you for the quick clarification.
Still, in the SFC Playground I posted above, any leading whitespaces I put into the input are trimmed in the div
, no matter if I use v-model.trim or not. That's what struck me as odd because it doesn't seem to make a difference.
It's because consecutive whitespaces are collapsed by default in HTML. If you replace the <h1>
element with <pre>
you'll see Vue's current behavior is correct.