VOOZH about

URL: https://www.geeksforgeeks.org/javascript/vue-js-v-if-directive/

⇱ Vue.js | v-if directive - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Vue.js | v-if directive

Last Updated : 15 Jul, 2025

The v-if directive is a Vue.js directive used to toggle the display CSS property of a element with a condition. If the condition is true it will make it visible else it will make it invisible. First, we will create a div element with id as app and let's apply the v-if directive to this element with data. Now we will create this data by initializing a Vue instance with the data attribute containing the value.

Syntax:

v-if="data"

Parameters: This directive accepts a single parameter which is the data or a condition. 
Example 1: This example uses VueJS to show an element with v-if.

Output:

👁 Image

Example 2: This example uses VueJS to show an element with v-if arithmetic conditions.

Output:

👁 Image
Comment
Article Tags: