当前位置:   article > 正文

element自定义菜单导航_el-menu自定义

el-menu自定义

1. router/menu.js

  1. "use strict";
  2. export default {
  3. notExists() {
  4. var notExist = [
  5. {
  6. pkId: 1,
  7. orderNum: 1,
  8. path: "'/404",
  9. title: "无效账户",
  10. ukName: "无效账户",
  11. icon: ""
  12. }
  13. ];
  14. return notExist;
  15. },
  16. meuns() {
  17. var arrs = [
  18. {
  19. pkId: "1",
  20. orderNum: "1",
  21. path: "/home",
  22. title: "政策管理",
  23. ukName: "政策管理",
  24. icon: "user",
  25. children: [
  26. {
  27. pkId: "11",
  28. orderNum: "11",
  29. path: "/backgroundPage",
  30. title: "政策管理",
  31. ukName: "政策管理",
  32. icon: "xin"
  33. },
  34. ]
  35. },
  36. {
  37. pkId: "2",
  38. orderNum: "2",
  39. title: "用户记录",
  40. ukName: "用户记录",
  41. icon: "xin",
  42. children: [
  43. {
  44. pkId: "21",
  45. orderNum: "21",
  46. path: "/home",
  47. title: "访问记录",
  48. ukName: "访问记录",
  49. icon: "xin"
  50. }
  51. ]
  52. },
  53. ];
  54. return arrs;
  55. }
  56. };

2.layout\components\Sidebar\index.vue 

  1. <el-scrollbar wrap-class="scrollbar-wrapper">
  2. <el-menu
  3. :default-active="activeMenu"
  4. :collapse="isCollapse"
  5. :background-color="variables.menuBg"
  6. :text-color="variables.menuText"
  7. :unique-opened="false"
  8. :active-text-color="variables.menuActiveText"
  9. :collapse-transition="false"
  10. mode="vertical"
  11. router>
  12. <!--<sidebar-item v-for="route in routes" :key="route.pkId" :item="route" :base-path="route.path" />-->
  13. <!--方式二:加载路由-->
  14. <sidebar-item :navMenus="routes"></sidebar-item><!--方式一:自定菜单-->
  15. </el-menu>
  16. </el-scrollbar>

 import Meun from "@/router/meun.js";

  1. routes() {
  2. return Meun.meuns();
  3. },

 

 

3.layout\components\Sidebar\SidebarItem.vue  

 

  1. <!--菜单子组件-->
  2. <template>
  3. <div class="navMenu">
  4. <label v-for="(navMenu,index) in navMenus" :key="index">
  5. <el-menu
  6. class="el-menu-vertical-demo"
  7. background-color="#3e3a58"
  8. text-color="#fff"
  9. active-text-color="#ffd04b"
  10. @select="handleSelect"
  11. :default-active="activeIndex"
  12. >
  13. <el-submenu :index="navMenu.ukName" v-if="navMenu.children">
  14. <template slot="title">
  15. <svg-icon :icon-class="navMenu.icon"/>
  16. <span>{{navMenu.ukName}}</span>
  17. </template>
  18. <el-menu-item v-for="(child,index) in navMenu.children" :key="index" :index="child.pkId" @click="childPath(child.path)">
  19. {{child.ukName}}
  20. </el-menu-item>
  21. </el-submenu>
  22. <el-menu-item :index="navMenu.ukName" v-else @click="toPath(navMenu.path)">
  23. <svg-icon :icon-class="navMenu.icon"/>
  24. <span slot="title">{{navMenu.ukName}}</span>
  25. </el-menu-item>
  26. </el-menu>
  27. </label>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'sidebar-item',
  33. props: ['navMenus'],
  34. data() {
  35. return {
  36. current:0,
  37. activeIndex:'1',
  38. }
  39. },
  40. methods: {
  41. addClass:function(index){
  42. this.current=index;
  43. },
  44. handleSelect(key, keyPath) {
  45. this.activeIndex=key;
  46. },
  47. childPath(keyPath){
  48. this.$router.push({path: keyPath})
  49. console.log(keyPath)
  50. },
  51. toPath(keyPath){
  52. this.$router.push({path: keyPath})
  53. console.log(keyPath)
  54. }
  55. }
  56. }
  57. </script>
  58. <style lang="scss" scoped>
  59. .el-menu-item{
  60. color: #ffffff!important;
  61. font-size: 14px;
  62. letter-spacing: 2px;
  63. vertical-align: middle;
  64. }
  65. .el-menu-item, .el-submenu__title {
  66. height: 50px;
  67. line-height: 50px;
  68. }
  69. .svg-icon{
  70. color: #ffffff;
  71. font-size: 22px;
  72. width: 1.2em!important;
  73. vertical-align: middle!important;
  74. }
  75. .active {
  76. color: #9ea0e9 !important;
  77. border-right: 10px solid;
  78. svg{
  79. color: #9ea0e9;
  80. }
  81. }
  82. .is-active{
  83. color: #9ea0e9 !important;
  84. background-color: #322e46 !important;
  85. }
  86. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/113191?site
推荐阅读
相关标签
  

闽ICP备14008679号