test.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <div :class="{'has-logo':showLogo}">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <el-scrollbar wrap-class="scrollbar-wrapper">
  5. <el-menu
  6. :default-active="activeMenu"
  7. :collapse="isCollapse"
  8. :background-color="variables.menuBg"
  9. :text-color="variables.menuText"
  10. :unique-opened="false"
  11. :active-text-color="variables.menuActiveText"
  12. :collapse-transition="false"
  13. mode="vertical"
  14. >
  15. <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
  16. </el-menu>
  17. </el-scrollbar>
  18. </div>
  19. </template>
  20. <script>
  21. import { mapGetters } from 'vuex'
  22. import Logo from './Logo'
  23. import SidebarItem from './SidebarItem'
  24. import variables from '@/styles/variables.scss'
  25. export default {
  26. components: { SidebarItem, Logo },
  27. computed: {
  28. ...mapGetters([
  29. 'sidebar'
  30. ]),
  31. routes() {
  32. return this.$router.options.routes
  33. },
  34. activeMenu() {
  35. const route = this.$route
  36. const { meta, path } = route
  37. // if set path, the sidebar will highlight the path you set
  38. if (meta.activeMenu) {
  39. return meta.activeMenu
  40. }
  41. return path
  42. },
  43. showLogo() {
  44. return this.$store.state.settings.sidebarLogo
  45. },
  46. variables() {
  47. return variables
  48. },
  49. isCollapse() {
  50. return !this.sidebar.opened
  51. }
  52. }
  53. }
  54. </script>