javascript - 模板中带有脚本标签的广告 [Vue.js]

标签 javascript html webpack vue.js

在我们的项目中,我们之前一直在使用 Thymeleaf,但现在我们转向 Vue.js,我们在使用相同的广告脚本时遇到了一些问题。脚本看起来像这样。我只更改了网址。

<script data-adfscript="sub.adcompany.net/asdf/?id=256746"></script>
<script src="//sub.adcompany.net/url/to/advertisement/script.js"  async="async" defer="defer"></script>

如果我们将这些标签放在 <template> 中,Webpack 给出以下信息:

Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as , as they will not be parsed.

所以我一直在谷歌上搜索以找到类似的案例。有一些插件可以为 Google Ads 执行此操作,但它们对我们不起作用。转义脚本标签 <\/script>以某种方式工作,但是直到 after 加载后脚本才添加到 DOM,因此它不会运行。

有人遇到过类似的问题吗?如果是这样,您的解决方案是什么?

Vue 文件看起来像这样:

<template>
  <aside class="sidebar-ad ui-wide">
    <script data-adfscript="sub.adcompany.net/asdf/?id=256746"></script>
    <script src="//sub.adcompany.net/url/to/advertisement/script.js"  async="async" defer="defer"></script>
  </aside>
</template>

<script>
    export default {
        data () {
            return {}
        }
    }
</script>

最佳答案

有一个解决方法。也适用于 style 标签。

<component is="script" src="https://www.example.com/example.js" async></component>

关于javascript - 模板中带有脚本标签的广告 [Vue.js],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45561612/

相关文章:

npm - WebStorm "Before Launch"– 等待完成

javascript - 从名称、值 JSON 数组中获取一项

javascript - 从显示中排除字符?

javascript - 下拉时 Div 背景颜色发生变化

javascript - 具有 iframe 非事件重定向的页面

javascript - React 热加载器配置

javascript - 如何在传单中设置 geoJSON FeatureCollection 的样式?

javascript - 如何将文本附加到同一 html 类中的多个用户输入?

javascript - JavaScript 运行时离开页面

node.js - ./node_modules/@angular/core/esm5/core.js 中的错误找不到模块 : TypeError: dep. isEqualResource 不是函数