- Vue.js 2.x by Example
- Mike Street
- 193字
- 2021-07-02 20:00:25
v-html
The v-html directive allows you to output content without using the mustache-style curly bracket syntax. It can also be used if your output contains HTML tags – it will render the output as HTML instead of plain text. The value of the HTML attribute is that of the data key or computed function name:
View:
In your view app space, add the v-html attribute to an element:
<p id="app">
<p v-html="message"></p>
</p>
JavaScript:
In the JavaScript, set the message variable to a string which contains some HTML elements:
const app = new Vue({
el: '#app',
data: {
message: '<h1>Hello!</h1>'
}
});
You should try and avoid adding HTML to your Vue instance, as it starts to mix up the View in the ViewModel and Model of our MVVM structure. There is also the danger you output an invalid HTML tag inside another. You should only use v-html with data you trust, because using it with an external API could be a security concern as it would allow the API to have control over your application. A potentially malicious API could use v-html to inject undesired content and HTML. Only use v-html with data you can fully trust.
- 大話PLC(輕松動漫版)
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- Spring 5.0 By Example
- Java 開發(fā)從入門到精通(第2版)
- INSTANT OpenCV Starter
- Mastering Python High Performance
- Getting Started with Laravel 4
- Android移動開發(fā)案例教程:基于Android Studio開發(fā)環(huán)境
- 石墨烯改性塑料
- 產品架構評估原理與方法
- HTML并不簡單:Web前端開發(fā)精進秘籍
- Mastering JavaScript Promises
- 可視化H5頁面設計與制作:Mugeda標準教程
- 趣學數據結構
- Java Web 從入門到項目實踐(超值版)