How to use components in v-html

前端 未结 1 1715
迷失自我
迷失自我 2020-12-02 00:16

I am trying to use components in v-html. I want to get html from own API, then I will show that.

Here is my code.

HTML:


&l         


        
相关标签:
1条回答
  • 2020-12-02 00:27

    Pretty sure Vuejs makes it very hard to directly use external html. v-html will simply replace the html content and therefore will not execute any directive. The purpose of it is to avoid XSS attacks as documented here: https://vuejs.org/v2/guide/syntax.html#Raw-HTML

    Dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to XSS vulnerabilities. Only use HTML interpolation on trusted content and never on user-provided content.

    If you really need to use external html, it is possible to use Vue.compile() documented here: https://vuejs.org/v2/api/#Vue-compile

    A working example can be found here: https://jsfiddle.net/Linusborg/1zdzu7k1/ and its related discussion can be found here: https://forum.vuejs.org/t/vue-compile-what-is-staticrenderfns-render-vs-staticrenderfns/3950/7

    0 讨论(0)
提交回复
热议问题