当前位置:   article > 正文

vue---element实现收缩展开的侧边导航栏_vue菜单栏重复

vue菜单栏重复

需求描述:

如下图,可收缩、可展开的侧边导航栏,当收缩时,鼠标悬停在一级菜单时,出现二级菜单。

                   

解决方法:

设置标志【isCollapse】来控制展开和收缩图标的显示,当【isCollapse=true】时,侧标导航栏收缩,且标题“通讯录管理”不显示。当【isCollapse=false】时,侧标导航栏展开,且标题“通讯录管理”显示。

在展开和收缩图标上绑定点击事件【@click="isCollapse=true"】【@click="isCollapse=false"】

  1. <span>
  2. <!-- <i class="el-icon-platform-eleme logo"></i> -->
  3. <img src="../../assets/images/通讯录.png" alt />
  4. <span v-show="!isCollapse">通讯录管理</span>
  5. </span>
  6. <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
  7. <i v-show="!isCollapse" class="el-icon-s-fold expandBtn" @click="isCollapse=true"></i>
  8. <i v-show="isCollapse" class="el-icon-s-fold shrinkBtn" @click="isCollapse=false"></i>
  9. </el-radio-group>

注意,收缩图标采用固定定位

  1. .shrinkBtn {
  2. position: fixed;
  3. left: -18px;
  4. top: 38px;
  5. color: #151d41;
  6. margin-left: 100px;
  7. transform: rotate(180deg);
  8. }

完整代码:

  1. <template>
  2. <div class="left-nav">
  3. <!-- <button @click="isCollapse=!isCollapse">展开</button> -->
  4. <div class="nav-logo">
  5. <span>
  6. <!-- <i class="el-icon-platform-eleme logo"></i> -->
  7. <img src="../../assets/images/通讯录.png" alt />
  8. <span v-show="!isCollapse">通讯录管理</span>
  9. </span>
  10. <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
  11. <i v-show="!isCollapse" class="el-icon-s-fold expandBtn" @click="isCollapse=true"></i>
  12. <i v-show="isCollapse" class="el-icon-s-fold shrinkBtn" @click="isCollapse=false"></i>
  13. </el-radio-group>
  14. </div>
  15. <el-menu
  16. class="el-menu-vertical-demo"
  17. :unique-opened="true"
  18. router
  19. background-color="#151d41"
  20. text-color="#fff"
  21. :collapse="isCollapse"
  22. >
  23. <el-menu-item index="/">
  24. <i class="el-icon-s-home"></i>
  25. <span slot="title">首页</span>
  26. </el-menu-item>
  27. <el-submenu v-for="(item,index) in menuList" :index="'' + index" :key="index">
  28. <template slot="title">
  29. <i :class="item.icon"></i>
  30. <span>{{ item.authName }}</span>
  31. </template>
  32. <el-menu-item
  33. v-for="(subItem,index) in item.children"
  34. :index="'/' + subItem.path"
  35. :key="index"
  36. >
  37. <span>{{ subItem.authName }}</span>
  38. </el-menu-item>
  39. </el-submenu>
  40. </el-menu>
  41. </div>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. menuList: [
  48. {
  49. id: 0,
  50. authName: "通讯录",
  51. icon: "el-icon-s-custom",
  52. children: [
  53. {
  54. authName: "用户与部门管理",
  55. id: 1,
  56. path: "department",
  57. parentid: 0
  58. },
  59. { authName: "通讯录设置", id: 2, path: "adrbook", parentid: 0 }
  60. ]
  61. },
  62. {
  63. id: 1,
  64. authName: "数据报表",
  65. icon: "el-icon-s-claim",
  66. children: [
  67. { authName: "数据概览", id: 1, path: "overview", parentid: 1 },
  68. { authName: "员工活跃数据", id: 2, path: "employees", parentid: 1 }
  69. ]
  70. },
  71. {
  72. id: 2,
  73. authName: "企业设置",
  74. icon: "el-icon-office-building",
  75. children: [
  76. {
  77. authName: "企业信息管理",
  78. id: 1,
  79. path: "information",
  80. parentid: 2
  81. },
  82. { authName: "权限管理", id: 2, path: "authority", parentid: 2 },
  83. { authName: "团队邀请设置", id: 3, path: "team", parentid: 2 },
  84. { authName: "安全策略", id: 4, path: "safety", parentid: 2 },
  85. { authName: "管理员日志", id: 5, path: "journal", parentid: 2 }
  86. ]
  87. }
  88. ],
  89. isCollapse: false
  90. };
  91. },
  92. methods: {}
  93. };
  94. </script>
  95. <style lang="less" scoped>
  96. @bgc: #151d41;
  97. .left-nav {
  98. // width: 228px;
  99. .nav-logo {
  100. height: 60px;
  101. padding: 0 10px;
  102. display: flex;
  103. justify-content: space-between;
  104. align-items: center;
  105. line-height: 60px;
  106. margin-top: 16px;
  107. .logo {
  108. font-size: 30px;
  109. }
  110. img {
  111. width: 28px;
  112. margin: 5px;
  113. }
  114. .el-radio-group {
  115. font-size: 20px;
  116. line-height: 60px;
  117. margin-top: 20px;
  118. margin-left: 10px;
  119. .shrinkBtn {
  120. position: fixed;
  121. left: -18px;
  122. top: 38px;
  123. color: #151d41;
  124. margin-left: 100px;
  125. transform: rotate(180deg);
  126. }
  127. }
  128. }
  129. .el-menu-vertical-demo:not(.el-menu--collapse) {
  130. width: 200px;
  131. min-height: 400px;
  132. }
  133. .el-menu-vertical-demo {
  134. border: none;
  135. .el-menu-item {
  136. span {
  137. color: #909399;
  138. font-size: 16px;
  139. }
  140. }
  141. .el-submenu {
  142. span {
  143. color: #909399;
  144. font-size: 16px;
  145. }
  146. .el-menu-item {
  147. span {
  148. color: #909399;
  149. font-size: 14px;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. </style>

 

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

闽ICP备14008679号