1
<Template>
   {{variable}}
</template>

<script>
 export default {
  data(){
   return {
    variable: "<ul><li>Sample</li><li>text></li></ul>"
   }
  }
 }
</script>

Expected result:

  • Sample
  • text

Actual Result: <ul><li>Sample</li><li>text</li></ul>

I need to display the html page. Where html codes are stored in the variable. for example, I have given the simple code above. Now the problem is the page takes the variable as string while displaying.

2 Answers 2

1

use v-html.

<Template>
  <div
     v-html="variable"
  </div>
</template>
Sign up to request clarification or add additional context in comments.

Comments

1

You can try this way, it will help:

--JS code --

new Vue({
    el: '#app',
  data: {
    variable: null,
  },
  created() {
    this.variable=`<ul><li>Sample</li><li>text</li></ul>`;
  },
});

-- HTML code --

<body>
   <Template>
   <div id="app">
   <div v-html="variable"></div>
   </div>
   </Template>
</body>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.