web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. AIGC工具
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    手机应用

vue项目引入谷歌广告报Adsense错误:TagError: adsbygoogle.push() error: All ins elements...解决方法

611 ℃

错误介绍:Vue项目开发中在指定的地方接入谷歌联盟广告(Google Adsense),报Uncaught TagError: adsbygoogle.push() error: All 'ins' elements in the DOM with class=adsbygoogle already have ads in them.​错误,下面web建站小编给大家简单介绍一下解决方法!

具体解决方法如下:

//在AdComponent.vue组件里添加以下代码
let adsenseUnitLength = document.getElementsByClassName('adsbygoogle');
window.onload = function () {
  for (let i = 0; i < adsenseUnitLength.length; i++) {
    (adsbygoogle = window.adsbygoogle || []).push({});
  }
};

完整代码如下:

//AdComponent组件
<template>  
  <div>  
    <ins class="adsbygoogle"
        style="display:block; text-align:center;"
        data-ad-layout="in-article"
        data-ad-format="fluid"
        data-ad-client="YOUR_AD_CLIENT_ID"
        data-ad-slot="YOUR_AD_CLIENT_ID"></ins>
  </div>  
</template>  
  
<script>  
export default {  
  name: 'AdComponent',
  data() {
    return {
      
    }
  },
   mounted() {
    //启动
    let adsenseUnitLength = document.getElementsByClassName('adsbygoogle');
    window.onload = function () {
      for (let i = 0; i < adsenseUnitLength.length; i++) {
        (adsbygoogle = window.adsbygoogle || []).push({});
      }
    };
  }
}  
</script>  
  
<style scoped>  
</style>

//在index.html引入通用script

Vue项目如何接入谷歌联盟广告(Google Adsense)

标签: Google Adsense, Vue联盟广告

上面是“vue项目引入谷歌广告报Adsense错误:TagError: adsbygoogle.push() error: All ins elements...解决方法”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_14431.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > vuejs
本文共计950个字,预计阅读时长7分钟

基金从业资格考试题库

一站式备考基金从业资格考试,收录2021-2025年模拟题库!呱呱工具箱

AI工作站

收录全球3800+ 款各行各业AI应用,轻轻松松做事!
生活小工具,收录了80多款小工具
上一篇: WordPress用自定义代码实现更高级的分页功能
下一篇: 车牌号输入HTML模板下载
x 打工人ai神器