網站首頁 編程語言 正文
這里使用到樹形控件的懶加載功能-直接上代碼
<el-tree
ref="selecteltree"
class="main-select-el-tree"
node-key="id"
highlight-current
:props="props"
:load="loadNode1"
lazy
@node-click="handleNodeClick"
></el-tree>
export default {
components: { VideoPlayer, RtmpPlayer },
name: "stock", // 要自動注冊init事件,必須等于文件名!
data() {
return {
// 自定義名
props: {
label: "name", // 自定義顯示
children: "zones",
isLeaf: "leaf",
},
},
methods: {
loadNode1(node, resolve) {
// node:當前點擊項的所有數據(包括返回數據) // resolve:渲染數據到當前項子節點
// 當前第一層: 自動調用接口拿到第一層的數據
if (node.level === 0) {
// 換成你需要的請求接口
api.getCountByDateTwo("001", "001").then((res) => {
if (res.data.code == 0) {
let data = res.data.data.value;
console.log(data);
// 這個是要的
return resolve(data);
}
});
}
// 判斷當前節點是否有下一層: 判斷條件看需求自定義
if (node.data && node.data.nodeType == "org") {
api.getCountByDateTwo(node.data.id, "001;1").then((res) => {
if (res.data.code == 0) {
let data = res.data.data.value;
console.log(data);
// 將子節點數據給到當前節點: 數據結構為數組套對象: [{},{}]
return resolve(data);
}
});
} else if (node.data && node.data.nodeType == "dev") {
api.getCountByDateTwo(node.data.id, "001;00;1").then((res) => {
if (res.data.code == 0) {
let data = res.data.data.value;
let list = [];
// 也可以直接改
data.forEach((el) => {
list.push({
name: el.name,
id: el.id,
nodeType: el.nodeType,
leaf: true, // 決定是否有子節點
});
});
console.log(list);
return resolve(list);
}
});
}
},
// 當前項點擊觸發: e為當前數據
handleNodeClick(e) {
console.log(e);
// this.$refs.selectTree.blur() // 收起tree
},
};
以上就是一個簡單的通過接口來獲取下層數據-并已樹形展示:elelment官方文檔上的懶加載就是這個
還有一種是帶有勾選框的: 需要改變源代碼來實現:后面有空在搞吧
原文鏈接:https://blog.csdn.net/m0_57884221/article/details/128116006
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2023-07-17 uniapp開發,打包成H5部署到服務器
- 2022-06-06 typescript中的泛型(genericParadigm)、interface、extends、
- 2022-05-23 ZooKeeper分布式協調服務設計核心概念及安裝配置_zabbix
- 2022-09-27 C#中對字符串進行壓縮和解壓的實現_C#教程
- 2022-07-16 Linux Redis-6.2.6單機部署
- 2022-01-17 什么是token token用在哪 token放在哪比較好
- 2022-03-12 Nginx熱部署的實現_nginx
- 2022-08-19 vscode遠程免密登入Linux服務器的配置方法_Linux
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支