In Vue 3, what is the core difference between
v-if and v-show?- a
v-ifonly works on components,v-showonly works on plain HTML elements - b
v-ifadds/removes the element from the DOM✓ - c
v-showcan use anelsebranch,v-ifcannot - dThere is no difference — they are interchangeable aliases
Explanation:
v-if conditionally renders (or destroys) the element and its component instance entirely — nothing exists in the DOM when false. v-show always renders the element and simply toggles the inline display: none CSS property, so the element stays in the DOM and keeps its component state.