element ui tree组件的节点全展开与收缩


```javascript
onExpandAll() {
  // 遍历tree结构修改展开与折叠是个异步行为,会耗时间,所以要写promise
  let task = new Promise((resolve, reject) => {
    this.expandAllStatus = !this.expandAllStatus;
    resolve();
  }).then(() => {
    this.treeNodeExpand(this.expandAllStatus)
  })
},
treeNodeExpand(status) {
  // 这是个耗时操作
  for(var i=0;i<this.$refs.myTree.store._getAllNodes().length;i++){
    this.$refs.myTree.store._getAllNodes()[i].expanded = status;
  }
},
// expandAllStatus: 是控制展开与折叠的状态(true/false)
// myTree: 自己的Tree ref名

转载:https://segmentfault.com/q/1010000012032027
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是生成 Element UI Tree 组件美化的代码,你可以根据需要自行调整样式: ```html <template> <el-tree :data="data" :props="defaultProps" node-key="id" show-checkbox default-expand-all :indent="20" highlight-current class="custom-tree" > <template #default="{ node, data }"> <span class="custom-tree-node"> <span class="custom-tree-node-label">{{ node.label }}</span> <span class="custom-tree-node-actions"> <el-button type="text" icon="el-icon-plus" size="mini"></el-button> <el-button type="text" icon="el-icon-edit" size="mini"></el-button> <el-button type="text" icon="el-icon-delete" size="mini"></el-button> </span> </span> </template> </el-tree> </template> <style scoped> .custom-tree { border: 1px solid #ebeef5; border-radius: 4px; background-color: #f2f6fc; padding: 10px; } .custom-tree-node { display: flex; align-items: center; justify-content: space-between; padding: 5px 10px; margin: 5px 0; border-radius: 4px; background-color: #fff; } .custom-tree-node-label { font-weight: bold; } .custom-tree-node-actions { display: flex; align-items: center; } .custom-tree-node-actions button { margin-left: 5px; padding: 0; } .custom-tree-node-actions button:hover { color: #409eff; } </style> ``` 解释: - `class="custom-tree"`:给树组件添加一个自定义的类名,方便样式定制。 - `template #default`:自定义节点的显示方式,包括节点的文本和操作按钮。 - `.custom-tree`:设置树组件的样式,包括边框、背景色和内边距等。 - `.custom-tree-node`:设置节点的样式,包括背景色、边距和圆角等。 - `.custom-tree-node-label`:设置节点文本的样式,包括加粗。 - `.custom-tree-node-actions`:设置操作按钮的样式,包括显示方式和对齐方式。 - `.custom-tree-node-actions button`:设置操作按钮的样式,包括间距和内边距。 - `.custom-tree-node-actions button:hover`:设置按钮的鼠标悬停样式,包括颜色。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值