accordion.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <el-tree
  3. :data="data"
  4. :props="defaultProps"
  5. accordion
  6. @node-click="handleNodeClick"
  7. />
  8. </template>
  9. <script lang="ts" setup>
  10. interface Tree {
  11. label: string
  12. children?: Tree[]
  13. }
  14. const handleNodeClick = (data: Tree) => {
  15. console.log(data)
  16. }
  17. const data: Tree[] = [
  18. {
  19. label: 'Level one 1',
  20. children: [
  21. {
  22. label: 'Level two 1-1',
  23. children: [
  24. {
  25. label: 'Level three 1-1-1',
  26. },
  27. ],
  28. },
  29. ],
  30. },
  31. {
  32. label: 'Level one 2',
  33. children: [
  34. {
  35. label: 'Level two 2-1',
  36. children: [
  37. {
  38. label: 'Level three 2-1-1',
  39. },
  40. ],
  41. },
  42. {
  43. label: 'Level two 2-2',
  44. children: [
  45. {
  46. label: 'Level three 2-2-1',
  47. },
  48. ],
  49. },
  50. ],
  51. },
  52. {
  53. label: 'Level one 3',
  54. children: [
  55. {
  56. label: 'Level two 3-1',
  57. children: [
  58. {
  59. label: 'Level three 3-1-1',
  60. },
  61. ],
  62. },
  63. {
  64. label: 'Level two 3-2',
  65. children: [
  66. {
  67. label: 'Level three 3-2-1',
  68. },
  69. ],
  70. },
  71. ],
  72. },
  73. ]
  74. const defaultProps = {
  75. children: 'children',
  76. label: 'label',
  77. }
  78. </script>