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

相关推荐
ct9781 天前
vue开发中核心API
前端·javascript·vue.js
Roc-xb1 天前
hermes-web-ui安装教程
前端·ui·hermes-web-ui
li星野1 天前
FastAPI 响应类型完全指南:从 JSON 到流式响应、异常处理与输出模型
前端·json·fastapi
ct9781 天前
vue-router + Pinia + Vuex
前端·javascript·vue.js
小雨下雨的雨1 天前
家庭药品管理系统智能过期预警鸿蒙PC Electron框架技术深度解析
前端·javascript·人工智能·华为·electron·鸿蒙·鸿蒙系统
ct9781 天前
vue2 + vue3差异点
前端·javascript·vue.js
小徐_23331 天前
程序员每天盯屏 10 小时,我开始认真研究“专业编程屏”这件事
前端
悟空瞎说1 天前
Git 协作工作流详解:从个人单打独斗到规模化团队协同
前端·git
颜进强1 天前
20-Spec-Kit Tasks 是怎么把技术方案拆成可执行任务的?
前端·后端·ai编程
程序员鱼皮1 天前
Cursor 零基础实战教程,夯爆了!带你速通 6 大核心能力
前端·后端·ai编程