Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Eval variable as HTML in vue

It might be basic question,however I can’t find the answer and I have no idea it is possible or not.

I am not familliar with vue

What I want to do is like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 <html>
 [[parse()]]
 </html>

new Vue({
 methods: {
  parse(){
    return "<div>test</div>"
  }
 }
});

Normally it shows the <div>test<div> as strings not html tags,

However I want to eval this return variable as html.

Is it possible?

>Solution :

Use the v-html directive:

new Vue({
  el: '#app',
  methods: {
    parse() {
      return '<div>test</div>'
    }
  }
})
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<div id="app">
  <div v-html="parse()"></div>
</div>

Make sure you read the warnings.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading