如何正确显示 contenteditable 内容? (laravel) (观点)

How to display contenteditable contents properly? (laravel) (vue)

下面#descrition里面的内容我已经保存了

<div id="description" contenteditable="true"></div>

我的问题是,当我尝试显示时,它不像 html 格式那样显示,而是像使用 <h1></h1><br> 保存的数据一样显示。它仅显示纯文本。

<div id="description" contenteditable="true">{{ $description }}</div>


我保存在我的数据库中并显示的内容:

<h1>Descriptoin</h1> Doner, where I built and maintained banner adverts and microsites. <br> And...

有人知道如何正确显示吗?


回答:感谢@Akram Wahid

在laravel - {!! $description !!}
在 vue 中 - <div v-html="description"> </div>

你必须这样做,因为 Blade {{ }} 语句会通过 PHP 的 htmlspecialchars 函数自动发送以防止 XSS attacks.If 你不希望你的数据被转义,您可以使用以下语法:

<div id="description" contenteditable="true">{!! $description !!}</div>

默认Laravel转义特殊字符以防止XSS攻击。 尝试使用这种格式:

<div id="description" contenteditable="true">{!! $description !!}</div>