1.

What is the v-show directive? Show with a simple example code.

Answer»
  • V-show - it is SIMILAR to the v-if directive as it is CONCERNED with showing or hiding DOM elements but it renders all elements to the DOM and uses show/hide CSS properties to show or hide elements in the DOM. It is used when we need frequent switching between on and off for a DOM element. 

<h1 v-show="ok">Hello!</h1> 

An element with a v-show which is ‘h1’ will always be rendered and remain in the DOM; v-show only toggles the display CSS property of the element. 

Example for V-show 

<div id="app">  <div v-show="showText">  <p>Show the first nice text</p>  </div>  <div v-show="!showText">  <p>Show the second bad text</p>  </div>  <button v-on:CLICK="showText = !showText">Toggle texts</button>  </div>  NEW Vue({  el: "#app",  data: {  showText: TRUE,  }  }) 

Result: 

  • This is the first nice text 
  • IF the ShowText is false 
  • This is the Second bad text 


Discussion

No Comment Found

Related InterviewSolutions