Conditional Rendering
Learn about conditional rendering in Vue using "v-if" and "v-else" directives.
We'll cover the following...
Vue.js allows the rendering of an HTML element or a block of elements based on a certain condition. This means that it is possible to dynamically render the webpage based on some logic. As the data
properties are bound to the template
, Vue.js updates the structure of the webpage automatically according to the current state of the properties. This is done through the v-if
, v-else
, and v-else-if
directives. In this lesson, the working of each of them is discussed separately.
v-if
The v-if
directive mounts an element in the DOM if the condition on which it depends is true, otherwise, it removes it from the DOM. For example, if there is a boolean variable in ...