<template>
<div id="app">
<el-menu v-if="seen" :default-active="activeIndex" class="el-menu-demo" menu-trigger="click"
text-color="#333" router mode="horizontal">
<el-menu-item index="/">首页</el-menu-item>
</el-menu>
</div>
</template>
<script>
export default {
name: "Layout",
data() {
return {
activeIndex: '/',
};
},
watch: {
$route() {
this.setCurrentRoute()
}
},
methods: {
setCurrentRoute() {
this.activeIndex = this.$route.path; //监听到当前路由状态并激活当前菜单
},
},
created() {
this.setCurrentRoute()
}
}
</script>
06-06
394
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)