鍍金池/ 問答/數(shù)據(jù)分析&挖掘  網(wǎng)絡安全  HTML/ vue2中如何添加站長統(tǒng)計代碼?

vue2中如何添加站長統(tǒng)計代碼?

clipboard.png

js代碼如下:

<script type="text/javascript">
   var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
   document.write(unescape("%3Cspan id='cnzz_stat_icon_1254949000'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.#/z_stat.php%3Fid%3D1254949000%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));
</script>

我在vue中調(diào)用如下:

clipboard.png

頁面渲染:

clipboard.png

正確渲染應該是:

clipboard.png

求問是什么原因?

回答
編輯回答
風清揚

你代碼都寫在div內(nèi)部了當然會按你顯示的那樣。一般都是下面這樣寫。

    var vds = document.createElement('script')
    vds.type = 'text/javascript'
    vds.async = true
    vds.src = (document.location.protocol === 'https:' ? 'https://' : 'http://') +
      'assets.growingio.com/vds.js'
    var s = document.getElementsByTagName('script')[0]
    s.parentNode.insertBefore(vds, s)
2017年5月25日 04:46
編輯回答
不歸路

我剛剛做了一個需求也有這個。我是將百度站長提供的代碼添加進了入口的index.html文件里面。個人也不能確定是這樣,等上線的時候去百度站長那邊看一下。

百度站長代碼:

<script> 
    var _hmt = _hmt || []; 
    (function() { 
        var hm = document.createElement("script"); 
        hm.src = "https://#/hm.js?*****"; 
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(hm, s); 
    })(); 
</script>
2018年2月13日 13:14