Vue Google 广告的配置

前置条件:已经在Google AdSense 中 添加网站 并通过审核 同时已创建广告单元。

因 VUE 的 Script 配置问题,所以不能直接拷贝内容。

index.html 配置

添加 Google 广告的脚本。

复制代码
//index.template.html
/* *
在head标签中添加 script
【 **** 】:你的发布商 ID
*/
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4797644559430915"
            crossorigin="anonymous"></script>

//index.template.html
//在body标签中为window添加函数
<body>
 
  <div id="q-app"></div>

<script>
    window['googlAdsense'] = function () {
        let chlid = document.getElementsByClassName('google-adsense-slot')
        for (let index = 0; index < chlid.length; index++) {
            (adsbygoogle = window.adsbygoogle || []).push({});
        }
    }
</script>
</body>

组件中

组件中添加应用。

复制代码
onMounted(() => {
   window.googlAdsense();
});

为广告添加占位符。

复制代码
//将广告单元代码添加到盒子中
<template>
            <div class="col google-adsense-slot">
              <ins
                  class="adsbygoogle"
                  style="display: block"
                  data-ad-client="ca-pub-4797644559430915"
                  data-ad-slot="4417932244"
                  data-ad-format="auto"
                  data-full-width-responsive="true"
              ></ins>
            </div>
</template>

https://www.isharkfly.com/t/vue-google/16438/1

相关推荐
石小石Orz9 分钟前
为什么推荐前端学习油猴脚本开发?
前端
珵煜ini12 分钟前
wd-button组件阻止事件冒泡的
前端
炒毛豆13 分钟前
vue3.4中的v-model的用法~
前端·vue.js
用户408128120038113 分钟前
大文件分片上传和断点续传
前端
极客悟道14 分钟前
颠覆传统虚拟化:在Docker容器中运行Windows系统的开源黑科技
前端·后端
前端康师傅15 分钟前
JavaScript 中你不知道的按位运算
前端·javascript
小桥风满袖17 分钟前
Three.js-硬要自学系列38之专项学习缓冲几何体
前端·css·three.js
Rubin9318 分钟前
埋点方案实现
前端
斯~内克22 分钟前
Centrifugo 深度解析:构建高性能实时应用的开源引擎
前端·开源
tianchang33 分钟前
策略模式(Strategy Pattern)深入解析与实战应用
前端·javascript·代码规范