Vue.js | v-show directive

The v-show directive is a Vue.js directive used to toggle the display CSS property of a element with our data. If the data 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-show directive to this element with data as a message. Now we will create this message by initializing a Vue instance with the data attribute containing either true or false.
Syntax:

v-show="data"

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

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>
            VueJS | v-show directive
        </title>
  
        <!-- Load Vuejs -->
        <script src=
        </script>
    </head>
  
    <body>
        <div style="text-align: center; width: 600px;">
            <h1 style="color: green;">
                GeeksforGeeks
            </h1>
            <b>
                VueJS | v-show directive
            </b>
        </div>
  
        <div id="canvas" style="border: 1px solid #000000;
                                width: 600px; height: 200px;">
            <div v-show="message" id="app">
                Hello I'm visible.
            </div>
        </div>
  
        <script>
            var app = new Vue({
                el: "#app",
                data: {
                    message: true,
                },
            });
        </script>
    </body>
</html>

chevron_right


Output:

Example 2: This example uses VueJS to hide an element with v-show.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        VueJS | v-show directive
    </title>
  
    <!-- Load Vuejs -->
    <script src=
    </script>
</head>
  
<body>
    <div style="text-align: center;width: 600px;">
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
        <b>
            VueJS | v-show directive
        </b>
    </div>
  
    <div id="canvas" style="border:1px solid #000000;
                            width: 600px;height: 200px;">
        <div v-show="message" id="app">
            Hello I'm invisible.
        </div>
    </div>
  
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                message: false
            }
        })
    </script>
</body>
  
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.