Tree Drop
Basic Drop
Use VTreeDrop
component to use tree in a dropdown
Show code
vue
<template>
<VTreeDrop :data="data" checkable />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { VTreeDrop } from '@wsfe/vue-tree'
const data = ref([
{
title: 'node-1',
id: 'node-1',
children: [
{
title: 'node-1-1',
id: 'node-1-1',
children: [
{
title: 'node-1-1-1',
id: 'node-1-1-1',
},
{
title: 'node-1-1-2',
id: 'node-1-1-2',
},
{
title: 'node-1-1-3',
id: 'node-1-1-3',
},
],
},
{
title: 'node-1-2',
id: 'node-1-2',
children: [
{
title: 'node-1-2-1',
id: 'node-1-2-1',
},
{
title: 'node-1-2-2',
id: 'node-1-2-2',
},
],
},
{
title: 'node-1-3',
id: 'node-1-3',
children: [
{
title: 'node-1-3-1',
id: 'node-1-3-1',
},
{
title: 'node-1-3-2',
id: 'node-1-3-2',
},
],
},
],
},
{
title: 'node-2',
id: 'node-2',
children: [
{
title: 'node-2-1',
id: 'node-2-1',
children: [
{
title: 'node-2-1-1',
id: 'node-2-1-1',
},
{
title: 'node-2-1-2',
id: 'node-2-1-2',
},
],
},
],
},
])
</script>
Customize Display of Input Content
You can use display
slot to customize the text value of input
Show code
vue
<template>
<VTreeDrop :data="data" checkable>
<template #display="scope">
<div
:style="{
width: '170px',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}"
>
{{ scope.checkedNodes.map((node) => node.title).join(',') }}
</div>
</template>
</VTreeDrop>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { VTreeDrop } from '@wsfe/vue-tree'
const data = ref([
{
title: 'node-1',
id: 'node-1',
children: [
{
title: 'node-1-1',
id: 'node-1-1',
children: [
{
title: 'node-1-1-1',
id: 'node-1-1-1',
},
{
title: 'node-1-1-2',
id: 'node-1-1-2',
},
{
title: 'node-1-1-3',
id: 'node-1-1-3',
},
],
},
{
title: 'node-1-2',
id: 'node-1-2',
children: [
{
title: 'node-1-2-1',
id: 'node-1-2-1',
},
{
title: 'node-1-2-2',
id: 'node-1-2-2',
},
],
},
{
title: 'node-1-3',
id: 'node-1-3',
children: [
{
title: 'node-1-3-1',
id: 'node-1-3-1',
},
{
title: 'node-1-3-2',
id: 'node-1-3-2',
},
],
},
],
},
{
title: 'node-2',
id: 'node-2',
children: [
{
title: 'node-2-1',
id: 'node-2-1',
children: [
{
title: 'node-2-1-1',
id: 'node-2-1-1',
},
{
title: 'node-2-1-2',
id: 'node-2-1-2',
},
],
},
],
},
])
</script>
Customize the Whole Dropdown Input
Use the default slot to replace the whole input component of the dropdown
Show code
vue
<template>
<VTreeDrop :data="data" checkable>
<template #default>
<div
:style="{
width: '170px',
cursor: 'pointer',
}"
>Click to show drop</div>
</template>
</VTreeDrop>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { VTreeDrop } from '@wsfe/vue-tree'
const data = ref([
{
title: 'node-1',
id: 'node-1',
children: [
{
title: 'node-1-1',
id: 'node-1-1',
children: [
{
title: 'node-1-1-1',
id: 'node-1-1-1',
},
{
title: 'node-1-1-2',
id: 'node-1-1-2',
},
{
title: 'node-1-1-3',
id: 'node-1-1-3',
},
],
},
{
title: 'node-1-2',
id: 'node-1-2',
children: [
{
title: 'node-1-2-1',
id: 'node-1-2-1',
},
{
title: 'node-1-2-2',
id: 'node-1-2-2',
},
],
},
{
title: 'node-1-3',
id: 'node-1-3',
children: [
{
title: 'node-1-3-1',
id: 'node-1-3-1',
},
{
title: 'node-1-3-2',
id: 'node-1-3-2',
},
],
},
],
},
{
title: 'node-2',
id: 'node-2',
children: [
{
title: 'node-2-1',
id: 'node-2-1',
children: [
{
title: 'node-2-1-1',
id: 'node-2-1-1',
},
{
title: 'node-2-1-2',
id: 'node-2-1-2',
},
],
},
],
},
])
</script>