SyntaxStudy
Sign Up
Vue.js v-if, v-else-if, v-else and v-show
Vue.js Beginner 1 min read

v-if, v-else-if, v-else and v-show

Conditional rendering in Vue is handled by `v-if`, `v-else-if`, and `v-else`. When `v-if` evaluates to false the element and its children are completely removed from the DOM, including all their event listeners and child components. This is genuine DOM destruction and recreation, making it slightly more expensive to toggle but ideal for elements that are infrequently shown or hidden. `v-show` keeps the element in the DOM at all times but toggles the CSS `display` property. Because the component is always mounted and its lifecycle hooks always run, `v-show` is more appropriate for frequently toggled elements where you want to avoid the cost of teardown and setup. When you need conditional rendering for a group of elements without adding a wrapper node to the DOM, wrap them in a `