数据结构:
{
id: 0,
label: '0'
children: [
{
id: 1,
label: '1',
children: [
{
id: 3,
label: '3'
}
]
},
{
id: 2,
label: '2'
}
]
}
采用递归的方法
// this.i = 0
getDepth(obj, k) {
this.i = Math.max(this.i, k)
if (obj.children) {
obj.children.forEach((v) => {
this.getDepth(v, k+1)
})
}
}
// 最深层级数 this.i