当前位置:   article > 正文

vue+elementui实现导航栏三级菜单动态显示_三级动态

三级动态
  1. <template>
  2. <el-container>
  3. <el-header>Header</el-header>
  4. <el-container>
  5. <el-aside width="200px">
  6. <el-col :span="24">
  7. <el-menu :router="true"
  8. class="el-menu-vertical-demo"
  9. @open="handleOpen"
  10. @close="handleClose"
  11. :default-active="this.$router.path"
  12. >
  13. <!--一级菜单-->
  14. <template v-for="item in menus">
  15. <el-submenu v-if="item.subMenu && item.subMenu.length" :index="item.url" :key="item.url">
  16. <template slot="title">
  17. <span>{{item.menuname}}</span>
  18. </template>
  19. <!--二级菜单-->
  20. <template v-for="itemChild in item.subMenu">
  21. <el-submenu v-if="itemChild.subMenu && itemChild.subMenu.length" :index="itemChild.url" :key="itemChild.url">
  22. <template slot="title">
  23. <span>{{itemChild.menuname}}</span>
  24. </template>
  25. <!--三级菜单-->
  26. <el-menu-item v-for="itemChild_child in itemChild.subMenu" :index="itemChild_child.url" :key="itemChild_child.url">
  27. <template slot="title">
  28. <span>{{itemChild_child.menuname}}</span>
  29. </template>
  30. </el-menu-item>
  31. </el-submenu>
  32. </template>
  33. </el-submenu>
  34. </template>
  35. </el-menu>
  36. </el-col>
  37. </el-aside>
  38. <el-main>
  39. <!-- 切换不同的组件,显示对应的内容 -->
  40. <router-view></router-view>
  41. </el-main>
  42. </el-container>
  43. </el-container>
  44. </template>
  45. <script>
  46. //导出
  47. export default {
  48. data() {
  49. return {
  50. menus: [],
  51. }
  52. },
  53. methods: {
  54. handleOpen(key, keyPath) {
  55. console.log(key, keyPath);
  56. },
  57. handleClose(key, keyPath) {
  58. console.log(key, keyPath);
  59. },
  60. queryMenus() {
  61. this.$axios.get("myMenu/initMenu/")
  62. .then(respData => {
  63. this.menus = respData.data;
  64. })
  65. .catch(errorData => {
  66. console.log(errorData);
  67. })
  68. },
  69. },
  70. mounted() {
  71. this.queryMenus();
  72. }
  73. }
  74. </script>
  75. <style>
  76. .el-header,
  77. .el-footer {
  78. background-color: #B3C0D1;
  79. color: #333;
  80. text-align: center;
  81. line-height: 60px;
  82. }
  83. .el-aside {
  84. background-color: #D3DCE6;
  85. color: #333;
  86. text-align: center;
  87. line-height: 200px;
  88. }
  89. .el-main {
  90. background-color: #E9EEF3;
  91. color: #333;
  92. text-align: center;
  93. line-height: 160px;
  94. }
  95. body>.el-container {
  96. margin-bottom: 40px;
  97. }
  98. .el-container:nth-child(5) .el-aside,
  99. .el-container:nth-child(6) .el-aside {
  100. line-height: 260px;
  101. }
  102. .el-container:nth-child(7) .el-aside {
  103. line-height: 320px;
  104. }
  105. html,
  106. body,
  107. #mydiv {
  108. margin: 0px;
  109. padding: 0px;
  110. height: 100%;
  111. }
  112. .el-container {
  113. height: 100%;
  114. }
  115. </style>

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