官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 宽城| 威信县| 平山县| 洛宁县| 正镶白旗| 通河县| 大厂| 青阳县| 沙河市| 美姑县| 涞源县| 琼海市| 平顺县| 纳雍县| 建湖县| 枣阳市| 祁连县| 通辽市| 石首市| 衡山县| 扶风县| 辽阳市| 靖江市| 吉安县| 阳山县| 昭通市| 池州市| 启东市| 惠东县| 海丰县| 龙川县| 佛冈县| 海门市| 邯郸县| 安岳县| 赫章县| 华坪县| 七台河市| 常熟市| 文山县| 旺苍县|