当前位置: 首页 > news >正文

el-tree 懒加载树

el-tree 懒加载树

  • 添加自定义图标
  • 指定叶子节点
  • 懒加载

<template><div><el-treeclass="filter-tree":data="treeData":props="defaultProps"ref="tree"lazy:load="loadTree":expand-on-click-node="true"@node-click="nodeClick"><span slot-scope="{ node, data }" class="span__"><imgclass="sxtImg"v-if="data.channelId && data.isOnline == 'true'"src="../../../../../assets/image/sxt1.png"alt=""title="设备在线"/><imgclass="sxtImg"v-if="data.channelId && data.isOnline != 'true'"src="../../../../../assets/image/sxt2.png"alt=""title="设备离线"/><span:class="[data.channelId && data.isOnline != 'true' ? 'offline' : 'online',]">{{ node.label }}</span></span></el-tree></div>
</template><script>
import { spTreeList } from "@/utils/api.js";
export default {data() {return {defaultProps: {children: "children",label: "name",isLeaf: (data) => {return data.channelId != null;  // ※ 指定哪种情况是最后一级(否则懒加载的树叶子节点前会有展开箭头,需要点一下才消失)},},treeData: [],};},mounted() {},methods: {nodeClick(data, node, comp) {if (data.channelId && data.isOnline != "true") {this.$message.error("当前设备离线!");return;}this.$emit("click", data, node.isLeaf);},// 懒加载加载方法,首次加载树的时候会被触发loadTree(node, resolve) {spTreeList({ orgCode: "" }).then((res) => {// this.rootNode = node;// this.rootResolve = resolve;let rootMainResolve = resolve;let treedata = [];if (node.level == 0) {treedata.push(res.data);return resolve(...treedata);}// 加载子级// if (node.data.isParent && node.data.parentId != "") {//   this.getChild(node.data, node.data.parentId, rootMainResolve);// } else {//   return resolve([]); // 防止不停转圈// }// 加载子级if (node.data.channelId) {return resolve([]); // 防止不停转圈} else {this.getChild(node.data, node.data.parentId, rootMainResolve);}});},getChild(data, type, resolve) {spTreeList({orgCode: data.id,}).then((res) => {return resolve(res.data);});},// 重新渲染树的根节点resetNode() {spTreeList({ orgCode: "" }).then((res) => {this.treedata = res.data;});},},
};
</script><style lang="scss" scoped>/deep/.el-tree-node__content {background: transparent;}/deep/ .el-tree__empty-block {background: transparent;}/deep/.el-tree {background: transparent;}/deep/.el-tree-node__label {color: #fff;}/deep/.el-tree-node__content:hover,/deep/.el-upload-list__item:hover {background: linear-gradient(90deg,rgba(74, 204, 255, 0.52),rgba(69, 122, 230, 0));position: relative;}/deep/.el-tree-node__content:hover::before {content: "";position: absolute;left: 0;top: 0;background: #4accff;width: 4px;height: 100%;}/deep/ .is-current > .el-tree-node__content {position: relative;background: linear-gradient(90deg,rgba(74, 204, 255, 0.52),rgba(69, 122, 230, 0));/deep/ .is-current > .el-tree-node__content::before {content: "";position: absolute;left: 0px;top: 0;background: #4accff;width: 4px;height: 100%;}}.online {color: #fff;
}
.offline {color: rgba(255, 255, 255, 0.6);
}.sxtImg {vertical-align: middle;margin-right: 5px;
}
</style>
http://www.lryc.cn/news/131982.html

相关文章:

  • 到江西赣州ibm维修服务器之旅-联想X3850 x6黄灯故障
  • VMware 虚拟机三种网络模式详解
  • ASP.NET指定变量数据类型,速度提高了100倍
  • PyArmor 一键加密
  • redis--持久化
  • 管理外部表
  • 数字图像处理-AWB跳变
  • DNNGP、DeepGS 和 DLGWAS模型构成对比
  • postgresSQL 配置文件设置
  • 【bug】Unity无法创建项目
  • 跨境外贸业务,选择动态IP还是静态IP?
  • Hlang社区-社区导航栏实现
  • Kestrel和ISS服务器下的配置
  • uniapp选择只选择月份demo效果(整理)
  • 微信ipad协议8.0.40 加好友功能
  • 如何通过本地搭建wamp服务器并实现无公网IP远程访问
  • matlab使用教程(19)—曲线拟合与一元方程求根
  • 【Go 基础篇】Go语言关键字和预定义标识符解析:探索编程的基石与核心要素
  • 微服务与Nacos概述-6
  • 不是说嵌入式是风口吗,那为什么工作还那么难找?
  • 【二叉树】114. 二叉树展开为链表
  • docker的安装与基础使用
  • python+django+mysql高校校园外卖点餐系统--计算机毕设项目
  • 获取excel中的图片(包含wps中嵌入单元格图片)
  • Git命令详解
  • 【STM32RT-Thread零基础入门】 4. 线程介绍(理论)
  • css学习3(三种样式表与样式控制优先级)
  • 【JS深层解析】内存
  • 第二章:25+ Python 数据操作教程(第十四节NUMPY 教程与练习)
  • Pycharm与Anaconda Python的开发环境搭建