背景:elementui中的树形控件中 有一个懒加载树形结构,每次点击一级才会加载出下一级,这样页面一加载只会显示一级菜单,如下图所示 这样看上去不直观,要求一进页面就列出一级菜单下面的一层 实现方法如下:
<el-tree
style="min-height: 613px; padding: 16px"
:props="propSetting"
:load="loadNode"
lazy
:highlight-current="true"
></el-tree>
async loadNode(node, resolve) {
if (node.level == 0) {
this.node=node
console.log(node)
this.resolve=resolve
let res = await getTopLeverTree(this.regionCode, true)
console.log(res)
let distRoot
if(res.length!=0){
distRoot = {
...res,
name: res[0].name,
label: res[0].name,
code:res[0].code
// nodekey: result.pkid,
// tid: result.pkid,
// disabled: true
};
this.$nextTick(() => {
console.log(node)
let nodedata = this.node.childNodes[0];
nodedata.expanded = true;
nodedata.loadData();
});
return resolve([distRoot]);
}
} else {
getSubLeverTree(node.data.code).then((response) => {
console.log(node.data.code);
response.forEach((item) => {
this.organCode.push(item.code);
});
this.listFilterForm.organCode = this.organCode;
this.findAll();
var data = response;
return resolve(data);
});
}
},
实现效果如下:页面一加载
|