mounted(){
if (window.performance.navigation.type == 1) {
console.log("页面被刷新!")
}else{
console.log("首次被加载!")
}
}
//还有一种方式就是通过检测路由的变化来判断是否页面被刷新
router.beforeEach((to,from,next)=>{
if (from.path === '/' && from.matched && from.matched.length === 0) {
isFirstEnter = true; // 记录路由是否为刷新
}
next();
})
本文介绍了如何在前端开发中检测页面是否被刷新,以及如何通过监控路由变化来判断用户的操作行为。通过window.performance.navigation.type属性和Vue.js的beforeEach钩子函数实现,适用于SPA应用。

6752

被折叠的 条评论
为什么被折叠?



