一、问题:后端数据值返回不统一,只能查完当前节点后,获取当前节点id做为参数再查询子节点.需要查询四个层级;有些子层级后面没有数据,但箭头还存在,点击后加载刷新,无数据箭头消失.
二、解决:使用leaf属性,指定显示当前数据的下一层级数据展示,如果子层级有数据,则数据展示,若不存在,则返回暂无数据
三、leaf官网解释:选项的叶子节点的标志位为选项对象的某个属性值
lazyLoad(node, resolve) {
const { level } = node;
if(level == 0) {
$postAxios(api.plantList, {},res => {
if (res && res.responseCode == 0) {
const nodes = res.data.map(item => ({
value: item.id,
label: item.plantName,
leaf: level >= 3//每一层级指定对应位置
}));
// 通过调用resolve返回子节点数据,通知组件数据加载完成
resolve(nodes);
} else {
this.$message.error(res.errorMessage);
}
})
}
if(level == 1) {
$postAxios(api.plantParticulars, node.data.value,res => {
if (res && res.responseCode == 0) {
const nodes = res.plantPeriods?.map((item) => {
return ({
value: item.id,
label: item.periodName,
leaf: level >= 2,
})
});
console.log(nodes);
resolve(nodes);
} else {
this.$message.error(res.errorMessage);
}
})
}
}
四、复原页面问题
五、解决后页面