Vue.js & Composition API (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
`v-if` vs. `v-show`: Performance and DOM Differences.
junior LevelFormsPerformance
In Simple Words:
v-if(Conditional Rendering):- "Real" conditional rendering: elements are physically added or removed from the DOM.
- Destroys and recreates child component instances and triggers lifecycle hooks (
onMounted/onUnmounted). - High toggle cost; low initial render cost if condition is false.
v-show(CSS Display Toggle):- Element is always rendered in the DOM.
- Only toggles the CSS
display: noneproperty. - Low toggle cost; higher initial render cost.
- Rule: Use
v-showfor elements that toggle frequently (dropdowns, tabs); usev-iffor elements that rarely change.