When Something Is Hidden vs When It Doesnât Exist: Understanding v-show in Vue
v-show controls visibility using CSS instead of removing elements from the DOM, making it efficient for frequently toggled UI.
At a glance, hiding something in a UI feels simple.
You either show it⌠or you donât.
So when you see this:
<p v-if="isVisible">Hello</p>It feels like the natural solution.
If itâs visible, render it.
If not, donât.
But thereâs a subtle detail hiding underneath that simplicity.
Because v-if is not actually âhidingâ anything.
Itâs removing it entirely.
The Difference You Donât See
When isVisible becomes false, Vue doesnât just make the element invisible.
It removes it from the DOM.
Itâs gone.
And when it becomes true again, Vue creates it from scratch.
So every toggle is not just a visual change.
Itâs a structural change.
A Different Kind of Control
Now consider this:
<p v-show="isVisible">Hello</p>At first, it looks identical.
But the behavior is completely different.
When isVisible is false, Vue doesnât remove the element.
It simply applies:
<p style="display: none;">Hello</p>The element is still there.
It just canât be seen.
Two Ways to Think About It
At this point, the distinction becomes clearer.
v-if answers the question:
âShould this exist?â
v-show answers a different one:
âShould this be visible?â
That difference is small in code.
But very real in behavior.
The Cost of Toggling
Now imagine a piece of UI that toggles frequently.
A dropdown.
A tooltip.
A modal.
With v-if, every toggle means:
- create the element
- mount it
- destroy it
- repeat
With v-show, the element is created once.
After that, toggling is just:
- show
- hide
- show
- hide
No reconstruction.
No lifecycle restart.
Just a change in visibility.
When Each One Makes Sense
This leads to a natural trade-off.
If something might never appear, or appears rarely, v-if makes sense.
You avoid rendering it entirely until needed.
If something toggles often, v-show is usually better.
You pay the cost once, then reuse it.
Neither is âbetterâ.
They optimize for different situations.
The Hidden Consequence
Thereâs another detail that often goes unnoticed.
Even when hidden, elements controlled by v-show still exist.
That means:
- they take up memory
- they run lifecycle hooks
- they can still be referenced
So âhiddenâ does not mean âinactiveâ.
It only means ânot visibleâ.
A Subtle Example
Consider this:
<div v-show="false">
<HeavyComponent />
</div>Even though itâs hidden, HeavyComponent is still created.
It still mounts.
It still runs its logic.
Because v-show never prevents rendering.
It only affects display.
A Shift in Perspective
At first, itâs easy to group v-if and v-show together.
They both control whether something appears.
But they operate at completely different levels.
v-if works at the structure level.
It changes what exists in the DOM.
v-show works at the presentation level.
It changes how something is displayed.
And that difference affects everything that follows.
The Bigger Insight
v-show exists because not every change in UI needs a structural update.
Sometimes, you donât need to rebuild anything.
You just need to toggle visibility.
And doing less work is often the better choice.
A Small Detail That Changes Behavior
At first, v-show feels like a minor alternative.
A convenience.
But once you understand what it actually does, it becomes something else.
A tool for controlling how much work your UI performs.
Because in the end, the real question isnât:
âShould this be shown?â
Itâs:
âShould this exist at all⌠or just be hidden?â