basic.vue 1.2 KB

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