前言:大家可能会遇到一个这样的问题,在监听页面中,是否有(如刷新,关闭等操作),刚好遇到有此类项目上的问题!!
问题:遇到了一个场景,当在浏览器(pc)上面按f5之类刷新 页面时,如果底部的tarbbar是自定义的话,会回到默认的第1个,解决方案如下:
[ vue-router的beforeRouteEnter的文档说明 ](导航守卫 | Vue Router (vuejs.org))
//利用vuerouter中的api方法监听页面是否在刷新操作
beforeRouteEnter(to, from, next) {
next(vm = >{
vm.tabbarList.filter((item, index) = >{
if (item.path === to.fullPath) {
vm.currentItem = index vm.currentPath = to.fullPath
}
})
})
},