Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse <br> in a string to html tag in VUE.js

I use {{}} in Vue.js to render my data to HTML. But now I got a string in my data, and I want the
tags in that string can be parsed into HTML tags when rendering data.

data(){
  return {
    bodyText: 'aaaaaa<br>aaaaaa'
}
}
<p>{{bodyText}}</p>

I want the content in span tag is like :

aaaaaa
aaaaaa

But the result is : aaaaaa<br>aaaaaa

like image 902
innocentDrifter Avatar asked Apr 10 '19 14:04

innocentDrifter


2 Answers

I think it should work using this:

<p>Using v-html directive: <span v-html="rawHtml"></span></p>
like image 162
lwolf Avatar answered Nov 05 '22 11:11

lwolf


Use v-html directive:

<p><span v-html="bodyText"></span></p>
like image 11
Psidom Avatar answered Nov 05 '22 11:11

Psidom