index.ts 527 B

1234567891011121314151617181920212223
  1. import router from '@/router'
  2. // 用于 router push
  3. window._hmt = window._hmt || []
  4. // HM_ID
  5. const HM_ID = import.meta.env.VITE_APP_BAIDU_CODE
  6. ;(function () {
  7. // 有值的时候,才开启
  8. if (!HM_ID) {
  9. return
  10. }
  11. const hm = document.createElement('script')
  12. hm.src = 'https://hm.baidu.com/hm.js?' + HM_ID
  13. const s = document.getElementsByTagName('script')[0]
  14. s.parentNode.insertBefore(hm, s)
  15. })()
  16. router.afterEach(function (to) {
  17. if (!HM_ID) {
  18. return
  19. }
  20. _hmt.push(['_trackPageview', to.fullPath])
  21. })