双大括号会将数据解释为普通文本,而非 HTML 代码。
想要输出真正的 HTML,你需要使用 [v-html 指令]。
// rawHtml: <span style="color: red">This should be red.</span>
<p>Using mustaches: {{ rawHtml }}</p>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
也就是带HTML的变量,可以用v-html展示。
下面是效果:
你的站点上动态渲染的任意 HTML 可能会非常危险,因为它很容易导致 [XSS 攻击]。请只对可信内容使用 HTML 插值,绝不要对用户提供的内容使用插值。