• element-ui el-menu 刷新保持高亮的写法


     1 <template>
     2   <el-menu
     3     :collapse="isCollapse"
     4     :default-active="defaultActive"
     5     class="el-menu-vertical-demo"
     6     background-color="#001529"
     7     text-color="#fff"
     8     active-text-color="#ffd04b"
     9   >
    10     <h3 v-show="isCollapse">
    11       <img src="../assets/images/logo.png" />
    12     </h3>
    13     <h3 v-show="!isCollapse">
    14       <img src="../assets/images/logo.png" />
    15       运维系统
    16     </h3>
    17     <el-menu-item :index="item.path" v-for="item in asideMenu" :key="item.path" @click="clickMenu(item)">
    18       <i :class="'el-icon-' + item.icon"></i>
    19       <span slot="title">{{ item.label }}</span>
    20     </el-menu-item>
    21   </el-menu>
    22 </template>
    23 
    24 <script>
    25 export default {
    26   computed: {
    27     isCollapse() {
    28       return this.$store.state.tab.isCollapse
    29     }
    30   },
    31   watch: {
    32     $route () {
    33       this.setCurrentRoute()
    34     }
    35   },
    36   data() {
    37     return {
    38       asideMenu: [
    39         {
    40           path: '/home',
    41           name: 'home',
    42           label: '巡检列表',
    43           icon: 'tickets'
    44         },
    45         {
    46           path: '/service-inspect',
    47           name: 'service-inspect',
    48           label: '新增巡检',
    49           icon: 'document-add'
    50         },
    51       ],
    52       defaultActive: '/home',
    53     }
    54   },
    55   created () {
    56     this.setCurrentRoute()
    57   },
    58   methods: {
    59     setCurrentRoute () {
    60       this.defaultActive = this.$route.path  //关键  通过他就可以监听到当前路由状态并激活当前菜单
    61     },
    62     clickMenu(item) {
    63       this.$router.push({ name: item.name })
    64       this.$store.commit('selectMenu', item)
    65     }
    66   }
    67 }
    68 </script>
    69 
    70 <style lang="scss" scoped>
    71 .el-menu {
    72   height: 100%;
    73   border: none;
    74   h3 {
    75     height: 64px;
    76     color: #ffffff;
    77     padding: 0 20px;
    78     font-size: 14px;
    79     text-align: center;
    80     display: flex;
    81     align-items: center;
    82     img {
    83        30px;
    84       height: 30px;
    85       margin-right: 5px;
    86     }
    87   }
    88 }
    89 .el-menu-vertical-demo:not(.el-menu--collapse) {
    90    160px;
    91 }
    92 </style>
  • 相关阅读:
    Vue
    自定义分页器
    selenium-确认进入了预期页面
    PyCharm常用快捷键(pycharm使用教程)
    Linux命令大全|linux常用命令
    ADB常用命令(adb常用命令)
    关于界面库
    VMWARE player 如何让 win2012 guest os 支持HYPER-V
    关于中文域名转码
    注册表中LEGACY残留项的清理技巧
  • 原文地址:https://www.cnblogs.com/guwufeiyang/p/14487430.html
Copyright © 2020-2023  润新知