Skip to main content
InterviewHubPRO
Section Overview
Q10

Question 10 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

20%
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: none property.
    • Low toggle cost; higher initial render cost.
  • Rule: Use v-show for elements that toggle frequently (dropdowns, tabs); use v-if for elements that rarely change.