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

相关推荐
掘金酱11 分钟前
TRAE Work 实战帮征文 | 获奖名单公示
前端·人工智能·后端
陆枫Larry17 分钟前
Chromium和Chrome到底是什么关系?
前端
a11177621 分钟前
模仿刀剑神域风格 作品集网页
前端·开源
a11177624 分钟前
Elemental Sandbox(元素沙盒)-Three.js 游戏技能特效
前端·开源
用户693717500138429 分钟前
前阵子刷屏的 Ox-Alpha 真身揭晓!GLM-5.3-Flash 上线,这价格真的杀疯了
前端·后端·github
四千岁35 分钟前
抓包LangChain-了解LangChain的原理
前端·javascript·后端
南雨北斗35 分钟前
TS方式构建Vue3 toast组件(一)
前端
IT小白杨37 分钟前
2026游戏工作室环境隔离指南:从设备指纹到移动IP的部署实践
前端·经验分享·网络协议·tcp/ip·游戏·安全架构·指纹浏览器
用户2986985301442 分钟前
使用 JavaScript 在 React 中实现 Word 转 PDF
前端·javascript·react.js
悟空瞎说1 小时前
UICollectionViewLayout 全套源码 + 逐行中文注释 + 使用场景说明
javascript