Display unescaped HTML in Vue.js

后端 未结 5 2103
孤城傲影
孤城傲影 2020-11-28 04:02

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

Small Vue app:

相关标签:
5条回答
  • 2020-11-28 04:33

    You can read that here

    If you use

    {{<br />}}
    

    it'll be escaped. If you want raw html, you gotta use

    {{{<br />}}}
    

    EDIT (Feb 5 2017): As @hitautodestruct points out, in vue 2 you should use v-html instead of triple curly braces.

    0 讨论(0)
  • 2020-11-28 04:37

    Vue by default ships with the v-html directive to show it, you bind it onto the element itself rather than using the normal moustache binding for string variables.

    So for your specific example you would need:

    <div id="logapp">    
        <table>
            <tbody>
                <tr v-repeat="logs">
                    <td v-html="fail"></td>
                    <td v-html="type"></td>
                    <td v-html="description"></td>
                    <td v-html="stamp"></td>
                    <td v-html="id"></td>
                </tr>
            </tbody>
        </table>
    </div>
    
    0 讨论(0)
  • 2020-11-28 04:40

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

    <td v-html="desc"></td>
    
    0 讨论(0)
  • 2020-11-28 04:50

    You have to use v-html directive for displaying html content inside a vue component

    <div v-html="html content data property"></div>
    
    0 讨论(0)
  • 2020-11-28 04:51

    Starting with Vue2, the triple braces were deprecated, you are to use v-html.

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

    It is unclear from the documentation link as to what we are supposed to place inside v-html, your variables goes inside v-html.

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

    If you want to see this live in an app, click here.

    0 讨论(0)
提交回复
热议问题