刷新浏览器
通过在mounted生命周期的方法里获取当前路由路径,然后匹配设置
浏览器后退和前进
通过watch监听路由变化,设置激活的导航
methods: {
setActiveNavItem(path) {
for (let navItem of this.nav.itemList) {
if (navItem.route === path) {
this.nav.defaultActive = navItem.id
}
}
}
},
watch: {
$route(to) {
this.setActiveNavItem(to.path)
}
},
mounted() {
this.setActiveNavItem(this.$route.path)
}