Vue 3 v-if Directive
v-if The directive is used for conditional rendering, deciding whether to render an element or template fragment based on the truthiness of an expression.
Basic Explanation
v-if The directive conditionally renders elements based on the truthiness of the bound expression. When the condition is true, the element is rendered into the DOM; when false, the element is not rendered.
- Expected type: any
- Purpose: conditional rendering, deciding whether to render an element based on the truthiness of an expression. Does not render the DOM when the condition is false.
Basic Usage
Example
Welcome back, user
Please log in
Used with v-else and v-else-if
v-if can be used together with v-else-if and v-else to form a condition chain:
Example
Loading...
Load failed
Content: {{ data }}
Vue 3 Built-in Directives