Home » vue » Rendering HTML from database in vuejs component in laravel

Rendering HTML from database in vuejs component in laravel

Posted by: admin November 26, 2021 Leave a comment

Questions:

I’m trying to fetch data from my database and display it as HTML content but it only turns out as a string, I’m using vuejs component in laravel. This is the code

<div id="main-window" v-for="post in posts">
<div class="post">
  <div class="content">
    {{post.content}}
  </div>
</div>

How can I use the post.content as HTML?

Answers:

You need to use v-html binding. Docs

<div id="main-window" v-for="post in posts">
  <div class="post">
    <div class="content" v-html="post.content">
  </div>
</div>