2

I am trying to render some html coming from an api. The v-html tag is outputting the <p> tags onto the page instead of treating them as html.

This is the data I am rendering:

Bio:"&lt;p&gt;Throughout his PhD and post-doctoral research, Dr David focussed on transdermal medical technology. While presenting his research at a skincare conference, he had his &quot;light-bulb moment&quot; realising the expertise he had developed could be reapplied to solve some of the major challenges facing the global cosmetic skincare industry. &lt;/p&gt;"

this is the html with the v-html

<div v-html="decodeURIComponent(teamMember.Bio)"></div>

I also tried

<div v-html="teamMember.Bio"></div>

and

<div v-html="decodeURI(teamMember.Bio)"></div>

but they all show the paragraph tags on the page instead of rendering.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Adam Adams
  • 63
  • 10

1 Answers1

3

I struggled with the same problem and found the solution like below;

computed: {
        parsedHtml () {
            const parser = new DOMParser();
            const elem = parser.parseFromString(this.teamMember.Bio, 'text/html');

            return elem.body.innerText;
        }
    }
AlpSenel
  • 190
  • 1
  • 12