Vue.js | v-show directive
Last Updated :
07 Jun, 2022
The v-show directive is a Vue.js directive used to toggle the display CSS property of a element with our data via inline styles. 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.
It also triggers transitions when its condition changes
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
<!DOCTYPE html>
< html >
< head >
< title >
VueJS | v-show directive
</ title >
< 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 >
|
Output:
Example 2: This example uses VueJS to hide an element with v-show.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
VueJS | v-show directive
</ title >
< 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 >
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...