如何在Vue中从数据库渲染HTML

问题描述 投票:1回答:2

我正在使用Vue.js作为前端和Node.js作为后端来制作博客应用。

我在前端使用富文本编辑器(vue2-editor),供用户创建博客内容。我想将该内容存储在数据库(MySQL)中并检索它。当前,无论我存储的内容是纯HTML格式。

<p><strong>This is Blog Heading</strong></p><p><br></p><p><u>This is underlined</u></p><p><br></p><p>This is start of the paragraph</p>

并且从数据库检索后,它呈现为字符串而不是HTML形式

如何获取以正确显示HTML?

mysql vue.js vuejs2 vue-component rich-text-editor
2个回答
2
投票

使用v-html将其显示为html而不是字符串。

您可以在这里了解更多信息:

https://vuejs.org/v2/guide/syntax.html

示例:

<div v-html="htmlFromDb" />

0
投票

据我所知,为您提供了一个解决方案,希望它将对您有所帮助。请看一下代码。

<p><strong>This is Blog Heading</strong></p>
<p><br></p>
<p><u>This is underlined</u></p>
<p><br></p>
<p>This is start of the paragraph</p>
© www.soinside.com 2019 - 2024. All rights reserved.