vue中v-text / v-html
vue中v-text / v-html使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue实例中的数据,事件和方法</title> </head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <body> <div id="root"> <h1 v-text="number"></h1> </div> <script type="text/javascript"> new Vue({ el:"#root", data:{ msg: "world", number:123 } }) </script> </body> </html>
显示123
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue实例中的数据,事件和方法</title> </head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <body> <div id="root"> <h1 v-html="content"></h1> </div> <script type="text/javascript"> new Vue({ el:"#root", data:{ content: "<h1>hello world</h1>", } }) </script> </body> </html>