Vue v-show Directive

Vue Tutorial

Vue v-show Directive

In Vue.js, the Vue v-show Directive is used to show or hide elements based on a condition without removing them from the DOM.

 What is Vue v-show Directive?

v-show controls an element’s visibility using CSS (display: none).

  • true → element is visible

  • false → element is hidden

  •  The element always exists in the DOM.

 Basic Example


 


v-show vs v-if (Important)

Featurev-showv-if
DOM PresenceAlways presentAdded / Removed
ImplementationCSS display: noneDOM manipulation
Initial LoadFasterSlower
Toggle PerformanceFasterSlower
Best Use CaseFrequent togglingRare conditions
  •  Use v-show for dropdowns, modals, tabs
  • Use v-if for authentication, permissions

v-show with Boolean Expressions


v-show Limitations

  •  Does NOT work with:

    • <template>

    • v-else

    • v-else-if

  • Cannot conditionally create/destroy components


v-show with Styling

Vue automatically adds:

You can combine with CSS transitions:


 Common Use Cases

  • Menus

  • Tooltips

  • Modals

  • Accordions

  • Tabs


 Key Points to Remember

  • v-show only hides/shows elements

  • Element remains in the DOM

  • Faster toggling than v-if

  • Not suitable for conditional rendering logic


 Conclusion

The v-show directive is perfect when you need quick visibility toggling without destroying elements.
Choose wisely between v-if and v-show for better performance.

You may also like...