Skip to content

All topics  /  Vue

Vue Js V-html Example Tutorial

Vue ·

Hi Guys,

In this example, I will explain you how to use V-html in vue.js, we will show basic example of vue js V-html. If you find yourself trying to compose templates using v-html, try to rethink the solution by using components instead.you can easliy use V-html in vue.js

Here, I will give you full example for simply V-html in vue js example as bellow.

Script Code


<script>
  Vue.config.devtools = true
  var app = new Vue({
    el:'#widget',
    data:{
         message: "<a href='//nicesnippets.com/'>//nicesnippets.com/</a>"
    }
  })
</script>

Full Example

<!DOCTYPE html>
<html>
<head>
  <title>Vue Js V-html Example</title>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/css/bootstrap.min.css">
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="bg-dark">
  <div class="container">
    <div class="col-md-6 offset-md-3">
      <div class="card mt-5">
        <div class="card-header">
          <h5>Vue Js V-html Example</h5>
        </div>
        <div class="card-body">
          <div class="row">
            <div class="col-md-12" >
              <div id="widget">
                {{ message }}    
                <h5 v-html="message"></h5>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>
<script>
  Vue.config.devtools = true
  var app = new Vue({
    el:'#widget',
    data:{
         message: "<a href='//nicesnippets.com/'>//nicesnippets.com/</a>"
    }
  })
</script>
</body>
</html>

It Will help you...