sidebar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="location-area">
  3. <div class="location-sidebar">
  4. <div @click="sidebarChange(item, index)" class="location-sidebar-list" :class="{'sidebar-active':index==current}" v-for="(item, index) in dataList" :key="index">
  5. {{item.name}}
  6. </div>
  7. </div>
  8. <div class="location-content">
  9. <div class="location-content-list" :class="{'location-content-active':index==lineCurrent}" v-for="(item, index) in dataList[current].children" :key="index" @click="checkSidebar(item, index)">
  10. {{item.name}}
  11. </div>
  12. </div>
  13. <div class="location-content-child" v-if="checkList.length>0">
  14. <div class="location-content-list-child" v-for="(item, index) in checkList" :key="index">
  15. {{item.name}}
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. props: {
  23. dataList: {
  24. type: Array
  25. }
  26. },
  27. data() {
  28. return {
  29. checkList: [],
  30. current: 0,
  31. lineCurrent: 0
  32. }
  33. },
  34. methods: {
  35. sidebarChange(item, index) {
  36. console.log(item);
  37. this.current = index
  38. if ( !item.children || item.children.length === 0) {
  39. this.checkList = [];
  40. } else {
  41. try {
  42. this.lineCurrent = 0
  43. this.checkList = JSON.parse(JSON.stringify(item.children[0].children));
  44. } catch (e) {
  45. this.checkList = [];
  46. }
  47. }
  48. console.log(this.checkList);
  49. },
  50. checkSidebar(item, index) {
  51. this.lineCurrent = index
  52. console.log(item);
  53. if (item.children) {
  54. this.checkList = item.children
  55. }
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .sidebar-active {
  62. color: #2979ff;
  63. // color: #fff;
  64. border-right: #2979ff 1px solid;
  65. }
  66. .location-content-active {
  67. color: #2979ff;
  68. border-right: #2979ff 1px solid;
  69. }
  70. .location-area {
  71. height: 40vh;
  72. overflow: hidden;
  73. display: flex;
  74. padding: 10px 0;
  75. .location-sidebar {
  76. width: 30%;
  77. height: 100%;
  78. overflow: auto;
  79. border-right: 1px solid #f3f3f3;
  80. // background: #f3f3f3;
  81. .location-sidebar-list {
  82. line-height: 50px;
  83. }
  84. }
  85. .location-content-list {
  86. line-height: 50px;
  87. padding: 0 10px;
  88. display: flex;
  89. text-align: left;
  90. }
  91. .location-content {
  92. flex: 1;
  93. background: #fff;
  94. height: 100%;
  95. overflow: auto;
  96. }
  97. .location-content-child {
  98. width: 50%;
  99. line-height: 50px;
  100. border-left: 1px solid #000;
  101. }
  102. }
  103. </style>