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.mzph.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…