vue資料繫結html

來源:互聯網
上載者:User

標籤:輸出   partial   使用   back   span   渲染   內容   class   vue   

html標籤的純文字顯示/被當做html標籤處理;

1)使用兩個大括弧時,假如字串內容是html標籤,那麼不會被轉義;

2)使用三個大括弧時,字串內的html標籤會被直接轉義

a.兩個大括弧:

 1 <div id="app">   2     {{html}}   3 </div>   4 <script>   5     var vm = new Vue({   6         el:"#app",   7         data: {   8             html:"<span>span</span>"   9         }  10     })  11 </script>  

輸出結果:

1 <span>span</span>  

b.三個大括弧:

 1 <div id="app">   2     {{{html}}}   3 </div>   4 <script>   5     var vm = new Vue({   6         el:"#app",   7         data: {   8             html:"<span>span</span>"   9         }  10     })  11 </script>  12 <script>  13     function load() {  14         vm.$mount("#app");  15     }  16 </script>  

輸出:

1 span

 3)插入內容的資料繫結無效(在沒有用partials的情況下),使用兩個大括弧,三個大括弧

 1 <div id="app">   2     {{{html}}}   3 </div>   4 <script>   5     var vm = new Vue({   6         el:"#app",   7         data: {   8             html: "<span>span{{val}}</span>",   9             val: "11"    10         }  11     })  12 </script>  13 <script>  14     function load() {  15         vm.$mount("#app");  16     }  17 </script>          

輸出:

span{{val}}

說明沒有資料繫結。

4)禁止在使用者提交的內容上動態渲染,否則會受到XSS攻擊

5)插值也可以用在html標籤的屬性中,例如class,或者id,或者其他。

但是Vue.js的指令和特殊性內是不可以用插值的。

 

vue資料繫結html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.