在 Vue.js 中显示未转义的 HTML [英] Display unescaped HTML in Vue.js

查看:23
本文介绍了在 Vue.js 中显示未转义的 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能在 mustache 绑定中解释 HTML?目前中断 (
) 只是显示/转义.

小型 Vue 应用程序:

var logapp = new Vue({el: '#logapp',数据: {title: '日志',日志:[{ 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 }]}})

这是模板:

<表格><tr v-repeat="日志"><td>{{失败}}</td><td>{{type}}</td><td>{{description}}</td><td>{{戳}}</td><td>{{id}}</td></tr></tbody>

解决方案

您可以使用指令 v-html 来显示它.像这样:

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

How can I manage to get HTML interpreted inside a mustache binding? At the moment the break (<br />) is just displayed/escaped.

Small Vue app:

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  }
    ]
  }
})

And here is the template:

<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>

解决方案

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

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

这篇关于在 Vue.js 中显示未转义的 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆