Home  >  Q&A  >  body text

Rendering unescaped HTML content in Vue.js

<p>How to parse HTML code in mustache binding? Currently newline characters (<code><br /></code>) will only be displayed/escaped. </p> <p>Small Vue application:</p> <pre class="brush:php;toolbar:false;">var logapp = new Vue({ el: '#logapp', data: { title: 'Logs', logs: [ { status: true, type: 'Import', desc: 'Learn<br />JavaScript', date: '11.11.2015', id: 1 }, { status: true, type: 'Import', desc: 'Learn<br />JavaScript', date: '11.11.2015', id: 1 } ] } })</pre> <p>The following is the template: </p> <pre class="brush:php;toolbar:false;"><div id="logapp"> <table> <tbody> <tr v-repeat="logs"> <td>{{fail}}</td> <td>{{type}}</td> <td>{{description}}</td> <td>{{stamp}}</td> <td>{{id}}</td> </tr> </tbody> </table> </div></pre></p>
P粉253518620P粉253518620449 days ago582

reply all(2)I'll reply

  • P粉939473759

    P粉9394737592023-08-22 17:15:45

    Starting from Vue2, the three curly braces are deprecated, you need to use v-html.

    <div v-html="task.html_content"> </div>

    It's not clear from the documentation link what we should put in v-html, your variables should be placed in v-html.

    Also, v-html only works with <div> or <span>, not <template> .

    If you want to see it live in the app, please click here.

    reply
    0
  • P粉399090746

    P粉3990907462023-08-22 15:03:22

    You can use the v-html directive to display it. like this:

    <td v-html="desc"></td>
    

    reply
    0
  • Cancelreply