I'm displaying content from ajax in a v-html element. The content contains a "pre" tag that i'd like to display as it should be.
Component :
<div v-html="content"></div>
Content example :
<h1>Title</h1>
<pre>
<p>Hello</p>
</pre>
What I get :
Title
Hello
What i'd like to get :
Title
<p>Hello</p>
Is there a way to achieve this ? Or is it impossible with v-html ?
EDIT :
I create the content from a form (wysiwyg). Before saving the content, it's encoded with he.js, so it looks like :
<h1>Title</h1>
<pre>
<p>Hello</p>
</pre>
After getting it with my ajax function, I encode it with he.js to get :
<h1>Title</h1>
<pre>
<p>Hello</p>
</pre>
Try with this content:
<h1>Title</h1>
<pre>
<p>Hello</p>
</pre>
So, you either have to escape the tags or separate the content of the pre tag from the rest of the HTML content.
I would personally do something like:
<div>
<h1>{{content.title}}</h1>
<pre>
{{content.code}}
</pre>
</div>
And in your data
you would have the content
object:
content: {
title: 'Title',
code: '<p>Hello</p>'
}
But I do not know your exact use case and whether the HTML structure of your content can change or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With