进入子路由也保持顶部菜单激活

This commit is contained in:
shiziyuan9527 2020-02-20 21:07:01 +08:00
parent 09d33859c8
commit 4bdd6630a1
1 changed files with 21 additions and 2 deletions

View File

@ -4,7 +4,8 @@
class="header-top-menus" class="header-top-menus"
text-color="#F2F2F2" text-color="#F2F2F2"
active-text-color="#fff" active-text-color="#fff"
:default-active="$route.path" :default-active="activeIndex"
@select="handleSelect"
router> router>
<el-menu-item index="1">功能测试</el-menu-item> <el-menu-item index="1">功能测试</el-menu-item>
<el-menu-item index="/createTest" onselectstart="return false">性能测试</el-menu-item> <el-menu-item index="/createTest" onselectstart="return false">性能测试</el-menu-item>
@ -14,7 +15,25 @@
<script> <script>
export default { export default {
name: "MsTopMenus" name: "MsTopMenus",
data() {
return {
activeIndex: '/'
}
},
watch: {
'$route' () {
this.handleSelect(this.activeIndex);
}
},
mounted () {
this.activeIndex = this.$route.matched[0].path || '/'
},
methods: {
handleSelect (index) {
this.activeIndex = index
}
}
} }
</script> </script>
<style> <style>