Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render HTML properly for JSON text in Vue component

Tags:

vue.js

vuejs2

I am iterating through a list of props that consists of simple HTML markup

<div class="columns medium-4 large-4" v-for="keyOffer in keyOffers">
  <p>{{ keyOffer.head }}</p>
  <p>{{ keyOffer.sub }}</p>
</div>

and one of the props looks like this

keyOffers: [
  {
    id: 'offerSecond',
    head: '4G network',
    sub: 'Dedicated to bringing you the <span class="u_underline">best mobile service</span>
  },
]

but in the output the <span> gets printed and not applied.

Any help?

like image 879
supersize Avatar asked Mar 06 '18 09:03

supersize


1 Answers

Use v-html directive:

<div class="columns medium-4 large-4" v-for="keyOffer in keyOffers">
  <p>{{ keyOffer.head }}</p>
  <p v-html="keyOffer.sub"></p>
</div>

Ref: RawHTML

like image 188
Sajib Khan Avatar answered Sep 22 '22 22:09

Sajib Khan