vue单页应用项目加入百度统计代码

登录百度统计管理界面之后把安装代码放到入口index.html对应位置。
 <script>
      var _hmt = _hmt || [];
      (function () {
//        百度统计
        var hm = document.createElement('script')
        hm.src = 'https://hm.baidu.com/hm.js?xxxxxx'
        var s = document.getElementsByTagName('script')[0]
        s.parentNode.insertBefore(hm, s)
      })()
    </script>
然后路由加入下列代码。
router.beforeEach((to, from, next) => {  
  // 统计代码  
  window._hmt.push(['_trackPageview', to.fullPath]);                                             
  next();                                            
}); 

  

原文地址:https://www.cnblogs.com/kaibo520/p/10402813.html