saytom
V2EX  ›  Vue.js

请教个 vue 中加载 google admanger 的问题

  •  
  •   saytom · May 11, 2021 · 1488 views
    This topic created in 1850 days ago, the information mentioned may be changed or developed.

    我在页面 A 和 B 中配置了谷歌广告代码,使用<route-link>在 AB 页面相互访问跳转的时候提示

    Exception in queued GPT command TypeError: Cannot read property 'addService' of null

    输入强制刷新浏览器就可以正常显示,把<route-link>换成<a>或者window.location就可以正常显示。 网上搜了下像是浏览器跳转重复渲染了谷歌的广告对象或者变量已经在缓存中了。

    methods:{
            initGGAd(){
                window.googletag = window.googletag || {cmd: []};
                googletag.cmd.push(function() {
                    googletag.defineSlot('XXndd-yst', ['fluid'], 'divXX-0').addService(googletag.pubads());
                    googletag.pubads().enableSingleRequest();
                    googletag.pubads().collapseEmptyDivs();
                    googletag.enableServices();
                });
                googletag.cmd.push(function() { googletag.display('div-gpt-XX'); });
            }
        },
        created() {
          this.initGGAd()
        }
    

    有哪位朋友了解怎么处理的不?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4276 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 00:59 · PVG 08:59 · LAX 17:59 · JFK 20:59
    ♥ Do have faith in what you're doing.