主要解决两个问题:
第一个:递归循环,这里是用 :is 动态指定组件来解决的。
第二个:同级如何区分,传入的数组中要提供相应的open数据,以供区分使用:is = 'open'
tree.vue代码
{{o.name}}
<script>
export default {
name: 'tree',
props: ['list', 'orgId'],
methods: {
showSubList (data) {
if (data.open) {
data.open = null
} else {
data.open = 'tree'
}
}
}
}
</script>
json数据
[{
"code": "nj",
"gmtCreate": null,
"gmtModified": null,
"list": null,
"name": "南京市",
"open": null,
"orderNum": 0,
"orgId": 2,
"parentId": 1,
"parentName": "江苏省",
"status": 1
}, {...}]
<component :is="currentView" :list="orgList" :orgId="0"></component>