VUE单页面添加百度统计

router.afterEach(() => {
  setTimeout(() => {
    var _hmt = _hmt || [];
    (function() {
      // 每次执行前,先移除上次插入的代码
      document.getElementById('baidu_tj') && document.getElementById('baidu_tj').remove()
      var hm = document.createElement('script')
      hm.src = 'https://hm.baidu.com/hm.js?XXXXXXXX'
      hm.id = 'baidu_tj'
      var s = document.getElementsByTagName('script')[0]
      s.parentNode.insertBefore(hm, s)
    })()
  }, 0)
})

猜你喜欢

转载自www.cnblogs.com/jackjo/p/9706613.html