Menu.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <el-menu
  3. :router="true"
  4. :default-active="defaultActive"
  5. class="el-menu-vertical-demo"
  6. @select="handleSelect"
  7. >
  8. <template v-for="(item,index) in data">
  9. <el-menu-item :index="'/'+role+'/'+item.code" v-if="item.subMenuList.length==0">
  10. <!-- <i v-bind:class="icons[item.code]"></i> -->
  11. <i class="el-icon-location"></i>
  12. <span slot="title">{{item.name}}</span>
  13. </el-menu-item>
  14. <el-submenu v-if="item.subMenuList.length>0" :index="index+1+''">
  15. <template slot="title">
  16. <i class="el-icon-location"></i>
  17. <span>{{item.name}}</span>
  18. </template>
  19. <el-menu-item v-for="(sub,i) in item.subMenuList" :index="'/'+role+'/'+sub.code">
  20. <p>{{sub.name}}</p>
  21. </el-menu-item>
  22. </el-submenu>
  23. </template>
  24. </el-menu>
  25. </template>
  26. <script>
  27. import config from '@api/config.js';
  28. export default {
  29. name: 'lt-menu',
  30. props: ['data', 'role'],
  31. data: function() {
  32. return {
  33. icons: config.menuIconList,
  34. defaultActive: ''
  35. };
  36. },
  37. computed: {
  38. defaultMItem: function() {
  39. let route = this.$route.path;
  40. return route;
  41. }
  42. },
  43. created() {
  44. // console.log(this.$route,'this.$route');
  45. this.defaultActive = this.$route.fullPath;
  46. // let menupath = localStorage.getItem('menuPath');
  47. // this.defaultActive = this.$route.fullPath;
  48. // console.log(this.defaultActive,'defaultActive');
  49. // console.log(menupath,'menupath');
  50. // if (this.$route.fullPath != menupath) {
  51. // this.defaultActive = menupath;
  52. // this.$router.push({ path: menupath });
  53. // } else {
  54. // this.defaultActive = this.$route.fullPath;
  55. // }
  56. },
  57. methods: {
  58. handleSelect(key, keyPath) {
  59. localStorage.setItem('menuPath', key);
  60. }
  61. }
  62. };
  63. </script>
  64. <style lang="less" scoped>
  65. .el-menu-item p {
  66. display: table-cell;
  67. vertical-align: middle;
  68. white-space: normal;
  69. line-height: 20px;
  70. height: 50px;
  71. }
  72. /*.el-menu-vertical-demo {
  73. min-width: 300px;
  74. }*/
  75. </style>