参考书籍《Vue.js快跑:构建触手可及的高性能Web应用》第1章 Vue.js基础-----1-10动态设置HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>数据的双向绑定</title> </head> <body> <div id="app"> <div v-html="innerHtml"></div> <div v-html="innerHtml2"></div> </div> <script src="https://unpkg.com/vue"></script> <script> new Vue({ el: "#app", data: { innerHtml: "<strong>this</strong>", innerHtml2: "< strong> this</strong>", } }) </script> </body> </html>
注意:innerHtml中的内容都不会被转义而是直接输出到页面上。
innerHtml