Using Vue2 v-html directive, is it possible to render rich text with `script`?
给我你的怀抱
给我你的怀抱 2017-06-26 10:56:14
0
3
1073

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~

给我你的怀抱
给我你的怀抱

reply all(3)
过去多啦不再A梦

No, vue will not render the script tag in the page. I want to insert a third-party advertising script. You have several ways

  1. Rewrite a page, vue load this iframe, this performance will be poor, you can use the srcdoc attribute of iframe, it will be better

  2. If it must be inserted into the page, then after the list rendering is completed, pass document.createElement('script'), and then appendenter the page

刘奇

Write a script command

给我你的怀抱

Post the code and look at the problem description. Isn’t it a good idea to write like this

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template