在nuxt.config.js 里
head: {
script:[
{src:'https://hm.baidu.com/hm.js?11e33451eefa929897300c1fc4ddf902'}
]
},
plugins: [
{src:'~/plugins/baidu.js'}
],
在plugin/baidu.js里
export default ({ app: { router }, store }) => {
router.afterEach((to, from) => {
/* 告诉增加一个PV */
try {
window._hmt = window._hmt || []
window._hmt.push(['_trackPageview', to.fullPath])
} catch (e) {}
})
}