sider.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <el-menu ref="menu" default-active="0" class="nav-menu" v-bind="themeStyles" :collapse="isCollapse" :router="false" :background-color="backgroundColor">
  3. <naf-menu-item
  4. v-for="(item, idx) in menuItems"
  5. :key="idx"
  6. :index="idx.toString()"
  7. :title="item.title"
  8. :options="item.options"
  9. :children="item.children"
  10. :target="item.target"
  11. :prefix="routerPrefix"
  12. @naf-menu-item="$emit('naf-menu-item', $event)"
  13. >
  14. </naf-menu-item>
  15. </el-menu>
  16. </template>
  17. <script>
  18. import NafMenuItem from './menu-item';
  19. export default {
  20. components: {
  21. NafMenuItem,
  22. },
  23. props: {
  24. theme: String,
  25. isCollapse: Boolean,
  26. menuItems: Array,
  27. routerPrefix: { type: String, default: '' },
  28. },
  29. data() {
  30. return {
  31. msg: 'Use Vue 2.0 Today!',
  32. // menus,
  33. };
  34. },
  35. // mounted: function() {
  36. // this.$nextTick(_ => {
  37. // // Code that will run only after the
  38. // // entire view has been rendered
  39. // this.$refs.menu.open('0');
  40. // });
  41. // },
  42. computed: {
  43. // 计算属性的 getter
  44. themeStyles() {
  45. // `this` 指向 vm 实例
  46. if (this.theme === 'dark') {
  47. // dark styles
  48. return {
  49. backgroundColor: '#545c64',
  50. textColor: '#fff',
  51. activeTextColor: '#ffd04b',
  52. };
  53. }
  54. // default styles
  55. return {
  56. backgroundColor: undefined,
  57. textColor: undefined,
  58. activeTextColor: undefined,
  59. };
  60. },
  61. backgroundColor() {
  62. return this.isCollapse ? '' : 'transparent';
  63. },
  64. },
  65. };
  66. </script>
  67. <style lang="less"></style>