Vue Conditional Rendering with v-if
Program Info
Program Code
×

Vue Conditional Rendering with v-if

We rendering conditional vue with the help of v-if.

Footer

×

Vue Conditional Rendering with v-if

<!DOCTYPE html>
<html>
<head>
  <title>Typewriters</title>
  <style>
    #app {
      border: dashed black 1px;
      width: 130px;
      padding-left: 20px;
      font-weight: bold;
      background-color: lightgreen;
    }
  </style>
</head>
<body>

<h1>Example with 'v-if' and 'v-else'</h1>

<p>Try changing the 'typewritersInStock' value in the Vue instance from 'true' to 'false' and run the code again.</p>

<div id="app">
  <p v-if="typewritersInStock">
    in stock
  </p>
  <p v-else>
    not in stock
  </p>
</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
  const app = Vue.createApp({
   data() {
    return {
      typewritersInStock: true
    }
   }
  })
  app.mount('#app')
</script>

</body>
</html>

Footer

Vue v-show Directive
Program Info
Program Code
×

Vue v-show Directive

We are using Vue v-show Directive. display the div element only if the showDiv property is set to true.

Footer

×

Vue v-show Directive

<!DOCTYPE html>
<html>
<head>
  <title>v-show</title>
  <style>
    #app {
      border: black dashed 1px;
      width: 200px;
      padding: 0 20px 20px 20px;
    }
    #app div {
      padding: 20px;
      background-color: lightgreen;
      font-weight: bold;
    }
  </style>
</head>
<body>

<h1>Example: v-show Visibility of Div Element</h1>

<div id="app">
  <p>Find the 'showDiv' data property in the code, change it to 'false', and run the code again.</p>
  <div v-show="showDiv">This div tag can be hidden</div>
</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
  const app = Vue.createApp({
    data() {
      return {
        showDiv: true
      }
    }
  })
 app.mount('#app')
</script>

</body>
</html>

Footer

Vue v-for Directive
Program Info
Program Code
×

Vue v-for Directive

We are using Vue v-for Directive. Display a list based on the items of an array.

Footer

×

Vue v-for Directive

<!DOCTYPE html>
<html>
<head>
  <title>My first Vue page</title>
  <style>
    #app > div {
      border: solid black 1px;
      width: 80%;
      padding: 10px;
      display: flex;
      flex-wrap: wrap;
    }
    img {
      width: 70px;
      margin: 10px;
    }
  </style>
</head>
<body>

<h1>Example: 'v-for' to create li-tags</h1>

<p>In this example 'v-for' creates an 'li' tag with the food name for each food item in the Vue instance array.</p>

<div id="app">

  <ol>
    <li v-for="x in manyFoods">{{ x }}</li>
  </ol>

</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

<script>
  const app = Vue.createApp({
   data() {
    return {
      manyFoods: [
        'Burrito',
        'Salad',
        'Cake',
        'Soup',
        'Fish',
        'Pizza',
        'Rice'
      ]
    }
   }
  })
  
  app.mount('#app')

</script>

</body>
</html>

Footer

Vue v-on Directive
Program Info
Program Code
×

Vue v-on Directive

We are using Vue v-on Directive. When the click event occurs the 'lightOn' data property is toggled between 'true' and 'false', making the yellow div behind the lightbulb visible or hidden.

Footer

×

Vue v-on Directive

<!DOCTYPE html>
<html>
<head>
  <title>Light Switch</title>
  <style>
    #app {
      border: dashed black 1px;
      display: inline-block;
      padding-bottom: 10px;
    }

    #app > button {
      display: block;
      margin: auto;
    }

    #lightDiv {
      position: relative;
      width: 150px;
      height: 150px;
    }

    #lightDiv > img {
      position: relative;
      width: 100%;
      height: 100%;
    }

    #lightDiv > div {
      position: absolute;
      top: 10%;
      left: 10%;
      width: 80%;
      height: 80%;
      border-radius: 50%;
      background-color: yellow;
    }
  </style>
</head>
<body>

<h1>Example: Light Switch</h1>
<p>The v-on directive is used on the button tag to listen to the 'click' event. When the 'click' event occurs the 'lightOn' data property is toggled between 'true' and 'false', making the yellow div behind the lightbulb visible/hidden.</p>
<div id="app">
  <div id="lightDiv">
    <div v-show="lightOn"></div>
    <img src="img_lightBulb.svg">
  </div>
  <button v-on:click=" lightOn =! lightOn ">Switch light</button>
</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
  const app = Vue.createApp({
    data() {
      return {
        lightOn: false
      }
    }
  })
 app.mount('#app')
</script>

</body>
</html>

Footer

Vue v-Method
Program Info
Program Code
×

Vue v-Method

We are using Vue v-Method. When the 'click' event occurs the 'writeText' method is called and the text is changed.

Footer

×

Vue v-Method

<!DOCTYPE html>
<html>
<head>
  <title>Click To Run Method</title>
  <style>
    #app {
      border: black dashed 1px;
      width: 200px;
      padding: 0 20px 20px 20px;
    }
    #app > div {
      width: 140px;
      height: 60px;
      background-color: lightgreen;
      padding: 20px;
      font-weight: bold;
      font-family: 'Courier New', Courier, monospace;
    }
  </style>
</head>
<body>

<h1>Example: Click to run a method</h1>

<div id="app">
  <p>Click on the box below:</p>
  <div v-on:click="changeText">
    {{ text }}
  </div>
</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
  const app = Vue.createApp({
    data() {
      return {
        text: ''
      }
    },
    methods: {
      changeText() {
        this.text = 'Hello World!'
      }
    }
  })
 app.mount('#app')
</script>

</body>
</html>

Footer

Vue v-bind Directive
Program Info
Program Code
×

Vue v-bind Directive

We are using Vue v-bind Directive. the font size depends on the Vue data property size.

Footer

×

Vue v-bind Directive

<!DOCTYPE html>
<html>
<head>
  <title>v-bind font-size</title>
  <style>
    #app > div {
      width: 200px;
      padding: 20px;
      border: dashed black 1px;
      background-color: lightcoral;
    }
  </style>
</head>
<body>

<h1>'v-bind' Font Size Example</h1>

<p>The browser sets the font-size based on the value of 'size' in the Vue instance.</p>

<div id="app">
  <div v-bind:style="{ fontSize: size }">Text example</div>
</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
  const app = Vue.createApp({
   data() {
    return {
      size: '28px'
    }
   }
  })
  app.mount('#app')
</script>

</body>
</html>

Footer


×

Name : Krishna Verma    |    Father's Name : Mr. Satish Kumar    |    Email ID : krishnaverma28081997@gmail.com    |    Religion : Hindu    |    Address : Dayampur, kanker khera, Meerut Cantt (250001), UP    |    Date of Birth : 28 August 1997    |    Marital Status : Non-Married    |    Place of Birth : Dayampur Kanker Khera Meerut Cantt.    |    Gender : Male    |    Age : 28    |    Contact : 9520335394    |    Father's Occupation : Sports man    |    Mother's Name : Smt. Kuntesh Devi    |    Mother's Occupation : Homemaker    |    Number of Brothers : 1    |    Number of Sisters : 1    |    Current Residence : Dayampur kanker khera meerut cantt    |    Family Type : Nuclear Family    |    Family Name : verma    |    Height : 5' 6''    |    Weight : 70 kg    |    Complexion : Fair    |    Body Type : Athletic    |    Hair Color : Black    |    Health Status : Good    |    Any Physical Disability : No    |    Highest Qualification : B.Tech (CSE)    |    Master Skill : PHP Laravel    |    Total Projects : 40 +    |    Total Skills : 25 +    |    Languages Known : Hindi and English    |    Website : krishnaportfolio.in    |    Siblings : 3    |    Nationality : Indian    |    Total Experience : 5 Years    |    LinkedIn : https://www.linkedin.com/in/krishna-verma-840b71356/    |    Total Programs : 10000    |    Total Projects : 40    |    Total Skills : 25    |    Total Experience : 5    |    Total DSA Problems : 165    |    Total Served Companies : 2