如何在v-html中运行脚本 [英] How to run script in v-html
本文介绍了如何在v-html中运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从数据库中获取嵌入代码(Instagram,Twitter等)。如何将它们绑定到vue组件?有没有办法在v-html中执行脚本标记?
I get embed codes (Instagram, Twitter and so on) from database. How to bind them to a vue component? Is there any way for executing script tag in v-html?
推荐答案
简答:你做不到。 dom加载后,你的浏览器就会阻止脚本标签的执行。
Short answer: You can't. Your browsers blocks the execution of script tags once the dom has loaded.
长答案:你可以尝试匹配脚本的src属性并获取+评估它,或者匹配div的内部内容并对其进行评估,但不建议这样做。
Long answer: You could try matching the src attribute of the script and fetch + evaluate it, or match the inner content of the div and evaluate it, but this is not recommended.
这篇关于如何在v-html中运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文