..._el-tree 关闭默认展开">
当前位置:   article > 正文

el-tree 展开关闭全部_el-tree 关闭默认展开

el-tree 关闭默认展开

最近使用 element-ui 中的 tree ,发现设置一个按钮展开关闭全部很难,想出下面的解决办法,解决了,但是感觉不是很好

思路主要就是 使用 v-if 控制 整个tree的显示隐藏,使它重新渲染

  1. <template>
  2. <div class='home-activity'>
  3. <div class="c-a-right">
  4. <el-button @click="open()">展开/关闭</el-button>
  5. <el-tree
  6. v-if="openOrNot"
  7. class="filter-tree"
  8. :data="data2"
  9. :props="defaultProps"
  10. :default-expand-all="defaultExpand"
  11. :filter-node-method="filterNode"
  12. node-key="navId"
  13. ref="tree">
  14. </el-tree>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'home-activity',
  21. components: {},
  22. data() {
  23. return {
  24. defaultExpand: true,
  25. openOrNot: true,
  26. data2: [{
  27. id: 1,
  28. label: '一级 1',
  29. children: [{
  30. id: 4,
  31. label: '二级 1-1',
  32. children: [{
  33. id: 9,
  34. label: '三级 1-1-1'
  35. }, {
  36. id: 10,
  37. label: '三级 1-1-2'
  38. }]
  39. }]
  40. }, {
  41. id: 2,
  42. label: '一级 2',
  43. children: [{
  44. id: 5,
  45. label: '二级 2-1'
  46. }, {
  47. id: 6,
  48. label: '二级 2-2'
  49. }]
  50. }, {
  51. id: 3,
  52. label: '一级 3',
  53. children: [{
  54. id: 7,
  55. label: '二级 3-1'
  56. }, {
  57. id: 8,
  58. label: '二级 3-2'
  59. }]
  60. }],
  61. defaultProps: {
  62.         id:'navId',
  63.         children: 'children',
  64. label: 'label',
  65.         disabled:'navOffOn'
  66.        },
  67. }
  68. },
  69. computed: {},
  70. watch: {},
  71. methods: {
  72. filterNode(value, data) {
  73. if (!value) return true;
  74. return data.label.indexOf(value) !== -1;
  75. },
  76. open() {
  77. this.defaultExpand = !this.defaultExpand
  78. this.openOrNot = false;
  79. setTimeout(() => {
  80. this.openOrNot = true;
  81. }, 10);
  82. }
  83. },
  84. created() {},
  85. mounted() {},
  86. beforeDestroy() {}
  87. }
  88. </script>
  89. <style lang='scss' scoped>
  90. .home-activity {
  91. width: 100%;
  92. height: 100%;
  93. }
  94. .d-header {
  95. color: white;
  96. .h-title {
  97. padding-top: 15px;
  98. }
  99. }
  100. .d-content {
  101. display: flex;
  102. .c-a-left {
  103. width: 30%;
  104. height: 100%;
  105. text-align: left;
  106. border-right: 2px solid $c-light-gray;
  107. }
  108. .c-a-right {
  109. width: 70%;
  110. height: 100%;
  111. }
  112. }
  113. </style>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/830671
推荐阅读
相关标签
  

闽ICP备14008679号