demo3.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div>
  3. <p class="title">自定义展开和选中</p>
  4. <m-tree
  5. :data="list"
  6. node-key="id"
  7. show-checkbox
  8. :default-expanded-keys="[1,4]"
  9. :default-checked-keys="[4]">
  10. </m-tree>
  11. </div>
  12. <div class="mt-50">
  13. <p class="title">展开所有项</p>
  14. <m-tree
  15. :data="list"
  16. node-key="id"
  17. show-checkbox
  18. default-expand-all>
  19. </m-tree>
  20. </div>
  21. </template>
  22. <script setup>
  23. const list = [
  24. {
  25. id: 1,
  26. label: '一级 1',
  27. children: [
  28. {
  29. id: 4,
  30. label: '二级 1-1',
  31. children: [
  32. {
  33. id: 10,
  34. label: '三级 1-1-1'
  35. },
  36. {
  37. id: 11,
  38. label: '三级 1-1-2'
  39. }
  40. ]
  41. },
  42. {
  43. id: 5,
  44. label: '二级 1-2'
  45. }
  46. ]
  47. },
  48. {
  49. id: 2,
  50. label: '一级 2',
  51. children: [
  52. {
  53. id: 6,
  54. label: '二级 2-1'
  55. },
  56. {
  57. id: 7,
  58. label: '二级 2-2'
  59. }
  60. ]
  61. },
  62. {
  63. id: 3,
  64. label: '一级 3',
  65. children: [
  66. {
  67. id: 8,
  68. label: '二级 3-1'
  69. },
  70. {
  71. id: 9,
  72. label: '二级 3-2'
  73. }
  74. ]
  75. }
  76. ]
  77. </script>
  78. <style scoped>
  79. .mt-50{
  80. margin-top: 50px;
  81. }
  82. .title{
  83. border-top: 1px solid #ddd;
  84. padding: 5px 0;
  85. }
  86. </style>