简体   繁体   English

为什么 v-html 不渲染 html

[英]Why is v-html not rendering html

I am trying to render some html coming from an api.我正在尝试呈现一些来自 api 的 html。 The v-html tag is outputting the <p> tags onto the page instead of treating them as html. v-html 标签将<p>标签输出到页面上,而不是将它们视为 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这是带有 v-html 的 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.但它们都在页面上显示段落标签而不是渲染。

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;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM