Skip to content

Instantly share code, notes, and snippets.

@techbysalma
Last active March 24, 2022 13:27
Show Gist options
  • Select an option

  • Save techbysalma/8b177650a863e5359bf85515cf10a2d1 to your computer and use it in GitHub Desktop.

Select an option

Save techbysalma/8b177650a863e5359bf85515cf10a2d1 to your computer and use it in GitHub Desktop.
<template>
<div>
<span>{{ branch.label }}</span>
<span
v-show="hasChildren"
>
🌠
</span>
<!-- add toggle function to show or hide children -->
<!-- try to use a flat array -->
<!-- add and delete children -->
</div>
<div
v-if="hasChildren"
:style="{ marginLeft: `${addSpacing}px`}"
>
<Tree
v-for="child in branch.children"
:key="child.id"
:branch="child"
:spacing="addSpacing"
/>
</div>
</template>
<script>
import { computed, onMounted, getCurrentInstance } from 'vue'
export default {
name: 'Tree',
props: {
branch: {
type: Object,
required: true
},
spacing: {
type: Number,
default: 0
}
},
setup(props) {
const hasChildren = computed(() => props.branch?.children?.length > 0)
const addSpacing = computed(() => props.spacing + 10 )
return {
hasChildren,
addSpacing
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment