vue项目中添加cnzz统计
作者:互联网
在App.vue中添加:
export default {
name: 'App',
mounted() {
// 创建cnzz统计js
const script = document.createElement('script')
script.src = 'https://v1.cnzz.com/z_stat.php?id=1111111111&web_id=1111111111'
script.language = 'JavaScript'
document.body.appendChild(script)
},
watch: {
'$route': {
handler(to, from) {
setTimeout(() => { //避免首次获取不到window._czc
if (window._czc) {
let location = window.location;
let contentUrl = location.pathname + location.hash;
let refererUrl = '/';
// 用于发送某个URL的PV统计请求,
window._czc.push(['_trackPageview', contentUrl, refererUrl])
window._czc.push(["_setAutoPageview", false]);
}
}, 300)
},
immediate: true // 首次进入页面即执行
}
}
}
免费查看前端面试 1000+
标签:vue,script,cnzz,window,添加,location,._,czc 来源: https://blog.csdn.net/weixin_42981560/article/details/112628808