webfansplz / vuejs-challenges

Collection of Vue.js challenges
https://vuejs-challenges.netlify.app/
MIT License
2.69k stars 188 forks source link

208 - 树组件 #2715

Open Li-mengbo opened 2 months ago

Li-mengbo commented 2 months ago
<script setup lang="ts">
interface TreeData {
  key: string
  title: string
  children: TreeData[]
}
defineProps<{data: TreeData[]}>()
</script>

<template>
 <div>
  <div v-for="(item, index) in data" :key="index">
    <span>{{ item.title }}</span>
    <TreeComponent v-if="item?.children?.length" :data="item.children" />
  </div>
 </div>
</template>