Vue Js Part: 7 (HTML Output Template Syntax)

You need to use v-html directive to show any html output in VueJS. See the example below:

<!DOCTYPE html>
<html lang="en">
<head>
   <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
     <div id="app">
       <div v-html="content"></div>
     </div>
     <script>
     new Vue ({
          el: '#app',
    data: {
            content: '<h2>Hello World</h2>'
    }
             })
   </script>
 </body>
</html>

Output:

Hello World

Display Image in VueJS

You need to use v-bind directive to display any image in VueJS. The general syntax (“Mustache” syntax) will not work here. Let us first give an example with general template syntax:

<html>
   <head>
      <title>VueJs Instance</title>
      <script type = "text/javascript" src = "https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
   </head>
   <body>
      <div id = "app">
         <h2>Firstname : {{firstname}}</h2>
         <h2>Lastname : {{lastname}}</h2>
         <div v-html = "htmlcontent"></div>
         <img src = "{{imgsrc}}" width = "300" height = "250" />
      </div>
      <script type="text/javascript">
         var vm = new Vue({
            el: '#app',
            data: {
               firstname : "Tortoiz",
               lastname  : "Themes",
               htmlcontent : "<div><h2>Vue Js Template</h2></div>",
   }
})
      </script>
   </body>
</html>
Notice, can’t get the image!
Let us now look at an example of displaying images using v-bind directive:
<html>
   <head>
      <title>VueJs Instance</title>
      <script type = "text/javascript" src = "https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
   </head>
   <body>
      <div id = "app">
         <h2>Firstname : {{firstname}}</h2>
         <h2>Lastname : {{lastname}}</h2>
         <div v-html = "htmlcontent"></div>
         <img v-bind:src = "imgsrc" width = "300" height = "250" />
      </div>
      <script type="text/javascript">
         var vm = new Vue({
            el: '#app',
            data: {
               firstname : "Tortoiz",
               lastname  : "Themes",
               htmlcontent : "<div><h2>Vue Js Template</h2></div>",
   }
})
      </script>
   </body>
</html>

Value show or hide toggling Template Syntax of HTML Element in VueJS:

Value show or hide toggling Template Syntax of HTML Element in VueJS:
To show or hide toggling the output of any html element in VueJS, you also need to use v-show directive. And it basically does the job using the CSS display property. However, it does not support the <template> element, nor does it work with v-else and v-else-if. See the example below:
<!DOCTYPE html>
<html lang="en">
<head>
   <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
     <div id="app">
         <div v-show="show">Hello World!</div>
     </div>
     <script>
     new Vue ({
            el: '#app',
        data: {
                show: true
        }
             })
   </script>
 </body>
</html>

Output

See another example:

<!DOCTYPE html>
<html lang="en">
<head>
   <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
     <div id="app">
       <div v-show="show">Hello World!</div>
     </div>
     <script>
     new Vue ({
          el: '#app',
          data: {
                  show: false
          }
      })
   </script>
 </body>
</html>

Output