Skip to content
Related Articles

Related Articles

Improve Article

Vue.js | v-html directive

  • Last Updated : 22 Jun, 2020
Geek Week

The v-html directive is a Vue.js directive used to update a element’s innerHTML with our data. This is what separates it from v-text which means while v-text accepts string and treats it as a string it will accept string and render it into HTML. First, we will create a div element with id as app and let’s apply the v-html 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 our message.

Syntax:

v-html="data"

Parameters: This directive accepts a single parameter which is the data. 
Example: This example uses VueJS to update the html of a element with v-html.

HTML




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

Output:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :