Could someone explain how whitespace is handled in SFC templates? #2969
Unanswered
stefandesu
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I've been struggling with an issue related to whitespace in SFC templates, and I don't really understand why it is how it is.
Let's consider these two templates (note that I'm using
{{ "Test" }}
just because there would usually be some variable):In the first example, there will be a space between "Test" and "Test2". However, in the second example, there will be no space, and I was not able to arrange it in any way so that a space is rendered, apart from adding a non-breaking space (which then needs to be enclosed in another template tag so that it's only rendered if both
condition1
andcondition2
are true). Note that it does not matter whether we usetemplate
orspan
or any other inline element.In Vue 2, there is a compiler option
preserveWhitespace
that seems to do the job, but I couldn't find anything like this for Vue 3/Vite. Is there any explanation for the above behavior? While I would like both examples to behave the same, I can live with simply understanding why the second example behaves differently, and then adjust accordingly.Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions