abu abu
abu abu

Reputation: 7022

Render HTML tags in Laravel & Vue.js

I am developing an application using Laravel & Vue.js. I have some data in database like Hello <b>world!</b>. How can I display them as Hello world! ?

Upvotes: 0

Views: 2014

Answers (1)

connexo
connexo

Reputation: 56754

Use the v-html binding:

<p v-html="fromDB"></p>

assuming you have a fromDB property in your viewmodel like e.g.

data() {
  return {
    fromDB: 'Hello <b>world!</b>'
  }
}

Example:

https://codesandbox.io/s/2po80169wy

Reference:

https://v2.vuejs.org/v2/guide/syntax.html#Raw-HTML

Please be aware that this comes with a risk since from your database, fromDB can become just about anything, e.g. <script>console.log('logged')</script>.

Upvotes: 6

Related Questions