vue加百度統計代碼(親測有效)

申請百度統計后,會得到一段JS代碼,需要插入到每個網頁中去,在Vue.js項目首先想到的可能就是,把統計代碼插入到index.html入口文件中,這樣就全局插入,每個頁面就都有了;這樣做就涉及到一個問題,Vue.js項目是單頁應用,每次用戶瀏覽網站時,訪問內頁時頁面是不會刷新的,也就意味著不會觸發百度統計代碼;所以最終在百度統計后臺看到的效果就是只統計到了網頁入口的流量,卻無法統計到內頁的訪問流量。

解決方法

main.js文件中調用vue-routerafterEach方法,將統計代碼加入到這個方法里面,這樣每次router發生改變的時候都會執行一下統計代碼,這樣就達到了目的,代碼如下:

router.afterEach( ( to, from, next ) => {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?xxxx";hm.id = "baidu_tj"var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(hm, s);})();},0);
} );

轉載自:https://blog.jae.sh/article/v924mq.html

轉載于:https://www.cnblogs.com/beileixinqing/p/8392695.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278492.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278492.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278492.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何將Rant變成生產力電動工具

Ranting doesn’t have to be a waste of breathe and time. You can turn a rant into a powerful tool for productivity. Learn how to transform your sense of victim hood and irritability to self-empowerment and mental clarity. 狂歡不必浪費呼吸和時間。 您可以將r…

linux 下使用 curl post

命令: curl -X POST -d /etc/lazada/lazada_tracking.txt http://localhost:8080/booking/rs/LazadaService/post --header "Content-Type:application/json" -d 后臺 / : post 的 body 體 eg: {"a…

服務治理·理論篇(一)

0、故事主角 呱呱樂 是一家互聯網金融公司。主營現金貸、p2p理財、消費分期業務。 公司現有技術人員800名,系統極其龐雜,每日穩定處理25w左右的訂單量,有搶購活動時,系統的QPS(Query Per Second)峰值達到了3w。 系統雖然龐雜&…

2019-1-92.4G射頻芯片培訓資料

2019-1-92.4G射頻芯片培訓資料 培訓 RF 小書匠 歡迎走進zozo的學習之旅。 2.4G芯片選型2.4G芯片開發Q&A2.4G芯片選型 芯片類型 soc防盜標簽2.4G無線芯片選型發射器收發器LSD2RF-1600-V1.1 調制方式射頻基礎 2.4G芯片開發 原理圖 發射優先收發均衡PCB topbottomlayout規…

在Outlook 2010中使用對話視圖

One of the new features in Outlook 2010 is the ability to use Conversation View for easier management of your email conversations. Here we will take a quick look at how to use the new feature. Outlook 2010中的新功能之一是可以使用“對話視圖”來更輕松地管理電…

openresty capture

local args {} args["name"] "張三" args["sex"] "男"local captureRes; if ngx.var.request_method "POST" thencaptureRes ngx.location.capture(/dsideal_yy/test, {method ngx.HTTP_POST, headers { ["Cont…

Day10:html和css

Day10:html和css <html> <body> <h1>標題</h1> <p>段落</p> </body> </html>HTML 是用來描述網頁的一種語言&#xff0c;超文本標記語言&#xff0c;不是一種編程語言&#xff0c;而是一種標記語言&#xff0c;是一套標記標簽…

如何在PowerPoint演示文稿中使用iTunes音樂

One of PowerPoint’s charms is its ability to play music during the presentation. Adding music to your presentation is simple, but using a song from your iTunes library requires a few extra steps. Here’s how to use iTunes music in PowerPoint. PowerPoint的…

Android:DELETE_FAILED_INTERNAL_ERROR Error while Installing APKs

Android studio DELETE_FAILED_INTERNAL_ERROR Error while Installing APKs 一、報錯信息 DELETE_FAILED_INTERNAL_ERRORError while Installing APKs 二、報錯原因 在一些機型上安裝軟件 提示卸載原先的軟件 但是又安裝不上新軟件 三、解決方法&#xff1a; File->Settin…

hotmail_在新的Hotmail Wave 4中禁用Messenger

hotmailAre you annoyed by having Messenger automatically sign in when you’re reading your emails in the new Hotmail? Here’s how you can disable the Web Messenger in Hotmail and other Windows Live online apps. 當您在新的Hotmail中閱讀電子郵件時&#xff0…

eclipse中將一個項目作為library導入另一個項目中

1. github上搜索viewpagerIndicator: https://github.com/JakeWharton/ViewPagerIndicator2. 下載zip包&#xff0c;解壓&#xff0c;eclipse中import->Android Existing Code->(注意只導入解壓后下面的Library)3. 導入后標記為Property->Android->isLibrary4. 將i…

論接單報價管理與ERP信息化管理的重要性

中小制造企業兩項比較重要的管理工作&#xff1a;接單報價管理與ERP信息化管理。大部分的中小制造企業都存在財務核算基礎薄弱、ERP信息化錯亂甚至沒有的情況。信息溝通不暢&#xff0c;經營過程數據與結果數據無法掌握是很多中小工廠的通病。樓主所知道的是&#xff0c;很多幾…

mac無法關機_Mac無法關機時該怎么辦

mac無法關機Razvan Franco Nitoi/Shutterstock.com拉茲萬佛朗哥尼托伊/Shutterstock.comMacs are like any other computer. Sometimes they won’t start up, and sometimes they won’t shut down. If your Mac is refusing to shut off, here’s how to shut it down anyway…

數串

數串 題目描述 設有n個正整數&#xff0c;將他們連接成一排&#xff0c;組成一個最大的多位整數。 如:n3時&#xff0c;3個整數13,312,343,連成的最大整數為34331213。 如:n4時,4個整數7,13,4,246連接成的最大整數為7424613。 輸入描述: 有多組測試樣例&#xff0c;每組測試樣…

chromebook刷機_如何在Chromebook上拍照

chromebook刷機Your Chromebook comes equipped with a built-in camera you can use to snap pictures to post to your social media accounts or share with friends and family. Here’s how to take a photo on a Chromebook. 您的Chromebook配備了一個內置攝像頭&#xf…

樹和二叉樹簡介

一、樹 1、什么是樹&#xff1f; 樹狀圖是一種數據結構&#xff0c;它是由n&#xff08;n>1&#xff09;個有限節點組成一個具有層次關系的集合。把它叫做“樹”是因為它看起來像一棵倒掛的樹&#xff0c;也就是說它是根朝上&#xff0c;而葉朝下的。它具有以下的特點&#…

對eventloop的研究

javasctipt是一門單線程的非阻塞的腳本語言&#xff0c;單線程意味著&#xff0c;JavaScript 單線程意味著&#xff0c;javascript代碼在執行的任何時候&#xff0c;都只有一個主線程來處理所有的任務。 JavaScript的事件分兩種&#xff0c;宏任務(macro-task)和微任務(micro-t…

【SSH高速進階】——struts2簡單的實例

近期剛剛入門struts2。這里做一個簡單的struts2實例來跟大家一起學習一下。 本例實現最簡單的登陸&#xff0c;僅包括兩個頁面&#xff1a;login.jsp 用來輸入username與password&#xff1b;success.jsp 為登陸成功頁面。error.jsp為登陸失敗頁面。 1、新建web項目“struts2”…

《智能家居》培訓第六天------2019-01-10

目錄&#xff1a; 一&#xff09;攝像頭 二&#xff09;照明 三&#xff09;所想 四&#xff09;總結 一&#xff09;攝像頭 攝像頭這塊學了跟沒學一樣我覺得&#xff0c;攝像頭給的api&#xff0c;yuyv轉rgb24也是給的api&#xff0c;總而言之就是&#xff0c;直接給了兩個源文…

在Linux上按大小列出文件和目錄

This page will show us how to create a list of files and folders ordered by size using standard Linux commands. 該頁面將向我們展示如何使用標準Linux命令創建按大小排序的文件和文件夾列表。 命令 (Command) To get a list with the size of each item in a folder, y…