el-tree 异步加载

注意:最后一级数据加

 leaf: true

1.

<el-tree  ref="tree"
lazy
:load="loadNode"
:default-expanded-keys="defaultExpandedKeys"
class="eltreecss"
:data="treeData" :props="defaultProps" @node-click="showtableList" highlight-current>
<span class="custom-tree-node" slot-scope="{ node, data }">
<span class="tabfrom">{{data.groupname}}({{ data.videonum}})</span>
</span>
</el-tree>

2.
data: function () {
treeData: [],//分组大类型

}

3.
loadNode(node, resolve) {
debugger
// const parentCode =node.level === 0 ? "-1": node.data.id;
if (node.level === 0) {
console.log('e',this.treeData);
this.treeData= [
{
description: null,
fatherpath: '001',
groupname: '按区域',
id:'0010002' ,
path: '0010002',
videonum: '3729'
},
{
description: null,
fatherpath: '004',
groupname: '按功能',
id:'0010004' ,
path: '0010004',
videonum: '830'
},
{
description: null,
fatherpath: '001',
groupname: '全部',
id:'4ec66a3d5e7edf56dc79fcf179c8d2dc' ,
path: '0010005',
videonum: '3958'
},
{
description: null,
fatherpath: '001',
groupname: '重点视频',
id:'0141e4f39f095700276edb2d86c8f6d5' ,
path: '0010007',
videonum: '0',
leaf: true
}
];
debugger
//return resolve([{ name: 'region' }]);
}
if (node.level >= 1) {
//传参请求接口子节点
const data=[ {
description: "",
fatherpath: "0010002",
groupname: "青岛市",
id: "51bba0e7fb5f1e30b7b9065a9151ce31",
path: "00100020001",
videonum: 0,
leaf: true
}, {
description: "",
fatherpath: "0010002",
groupname: "济南市",
id: "51bba0e7fb5f1e30b7b9065a9151ce31",
path: "00100020001",
videonum: 0,
}]
resolve(data);
}
},
4.节点点击事件
showtableList(data,node,nod){
debugger
this.currentNode=node;
this.defaultExpandedKeys.push(data.id);
}
posted @ 2022-04-14 10:49  简单就好zyx  阅读(435)  评论(0编辑  收藏  举报