繁体   English   中英

为什么 v-html 不渲染 html

[英]Why is v-html not rendering html

我正在尝试呈现一些来自 api 的 html。 v-html 标签将<p>标签输出到页面上,而不是将它们视为 html。

这是我渲染的数据:

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

这是带有 v-html 的 html

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

我也试过

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

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

但它们都在页面上显示段落标签而不是渲染。

我遇到了同样的问题,并找到了如下解决方案;

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