You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
725 B
Vue

<template>
<li>
<!-- 节点标题 + 展开按钮 -->
<div @click="toggleExpand(node)">
<span v-if="hasChildren">{{ node.expanded ? "" : "" }}</span>
{{ node.Name }}
</div>
<!-- -->
<ul v-if="hasChildren">
<TreeItem v-for="child in node.children" :key="child.Id" :node="child" />
</ul>
</li>
</template>
<script setup>
import { computed } from "vue";
const props = defineProps({
node: Object, // 节点数据
});
// 检查是否有子节点
const hasChildren = computed(() => props.node.children?.length > 0);
// 切换展开状态
const toggleExpand = (node) => {
if (hasChildren.value) {
node.expanded = !node.expanded;
}
};
</script>