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

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.

主站蜘蛛池模板: 金山区| 昆明市| 五寨县| 黄冈市| 岳阳市| 上思县| 张家界市| 衡阳县| 十堰市| 武夷山市| 桐庐县| 藁城市| 富蕴县| 深泽县| 华宁县| 泸州市| 兖州市| 清徐县| 宁陵县| 林西县| 陇南市| 湟源县| 横峰县| 黔西| 柯坪县| 大庆市| 汶上县| 广河县| 盘山县| 廉江市| 涞水县| 镇赉县| 邓州市| 丰顺县| 雷山县| 什邡市| 农安县| 宜阳县| 清新县| 苍梧县| 东阿县|