I want a piece of rich text to be rendered in vue, but this rich text contains a script
statement. I tested it locally and did not execute the statement.
How to solve this problem?
Sample code:
<template>
<p v-html="testHtml"></p>
</template>
<script>
export default {
data () {
return {
testHtml: '<p><script>console.log("test")</script><p><span>测试测试</span></p><p>'
}
}
}
</script>
Thank you~
No,
vue
will not render thescript
tag in the page. I want to insert a third-party advertising script. You have several waysRewrite a page,
vue
load thisiframe
, this performance will be poor, you can use thesrcdoc
attribute ofiframe
, it will be betterIf it must be inserted into the page, then after the list rendering is completed, pass
document.createElement('script')
, and thenappend
enter the pageWrite a script command
Post the code and look at the problem description. Isn’t it a good idea to write like this