data () {
return {
list: [{
name: 'xiaoming',
id: 1,
children: [
{
name: 'xiaoming2',
id: 2,
children: []
},
{
name: 'xiaoming3',
id: 3,
children: [
{
name: 'xiaoming5',
id: 5
},
{
name: 'xiaoming5',
id: 5
}
]
}
]
}]
}
},
methods: {
digui (arr) {
arr.forEach(v => {
if (v.children instanceof Array) {
this.digui(v.children)
} else {
v.children = {
text: 'haha',
text2: 'xixi'
}
}
});
}
},
mounted () {
this.digui(this.list);
console.log(this.list)
}
递归数组,给最里层的数据添加节点
最新推荐文章于 2024-07-22 23:12:07 发布