Использование
Компонент Tree показывает элементы с вложенностью: структуру отделов, папки Диска, разделы каталога товаров. Ветку можно раскрыть и свернуть, элемент — выбрать.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree :items="items" />
</template>
Элементы
Пропс items — массив объектов со свойствами:
icon?: IconProplabel?: stringtrailingIcon?: IconPropdefaultExpanded?: booleandisabled?: booleanslot?: stringchildren?: TreeItem[]onToggle?: (e: TreeItemToggleEvent<TreeItem>) => voidonSelect?: (e: TreeItemSelectEvent<TreeItem>) => voidclass?: anyb24ui?: { item?: ClassNameValue, itemWithChildren?: ClassNameValue, link?: ClassNameValue, linkLeadingIcon?: ClassNameValue, linkLabel?: ClassNameValue, linkTrailing?: ClassNameValue, linkTrailingIcon?: ClassNameValue, listWithChildren?: ClassNameValue }
get-key ключом служит label. Лучше передать функцию get-key, которая вернёт уникальный идентификатор, или указать в labelKey, какое свойство брать.<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree :items="items" />
</template>
Множественный выбор
Пропс multiple разрешает выбрать несколько элементов.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree multiple :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree multiple :items="items" />
</template>
Вложенность
Пропс nested решает, рисовать ли дерево вложенными списками или одним плоским списком с отступами. По умолчанию true.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree :nested="false" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree :nested="false" :items="items" />
</template>
nested: false все элементы стоят на одном уровне, а уровень показан отступом. Так удобнее для виртуализации и перетаскивания.Цвет
Пропс color задаёт цвет выбранного элемента.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree color="air-primary-success" :default-value="{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
}" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree color="air-primary-success" :default-value="{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
}" :items="items" />
</template>
Размер
Пропс size меняет размер дерева.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree size="xl" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree size="xl" :items="items" />
</template>
Значок справа
Пропс trailing-icon меняет значок справа у ветки. По умолчанию — i-bx24-outline-chevron-down-l.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
trailingIcon: 'i-bx24-outline-chevron-down-l',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree trailing-icon="i-bx24-actions-arrow-to-the-right" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
trailingIcon: 'i-bx24-outline-chevron-down-l',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree trailing-icon="i-bx24-actions-arrow-to-the-right" :items="items" />
</template>
Значки раскрытой и свёрнутой ветки
Пропсы expanded-icon и collapsed-icon задают значок ветки, когда она раскрыта и когда свёрнута. По умолчанию — i-bx24-solid-folder и i-bx24-outline-folder.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree expanded-icon="i-bx24-main-open-book" collapsed-icon="i-bx24-crm-book-open" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж/',
defaultExpanded: true,
children: [
{
label: 'Договоры/',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты/',
defaultExpanded: true,
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree expanded-icon="i-bx24-main-open-book" collapsed-icon="i-bx24-crm-book-open" :items="items" />
</template>
Отключение
Пропс disabled запрещает любые действия с деревом.
<script setup lang="ts">
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж',
icon: 'i-bx24-outline-folder',
defaultExpanded: true,
children: [
{
label: 'Договоры',
icon: 'i-bx24-outline-folder',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты',
icon: 'i-bx24-outline-folder',
children: [
{
label: 'Квартал',
icon: 'i-bx24-outline-folder',
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree disabled :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { TreeItem } from '@bxshefby/b24ui-nuxt'
const items = ref<TreeItem[]>([
{
label: 'Отдел продаж',
icon: 'i-bx24-outline-folder',
defaultExpanded: true,
children: [
{
label: 'Договоры',
icon: 'i-bx24-outline-folder',
children: [
{
label: 'Договор поставки.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Счёт 1045.pdf',
icon: 'i-bx24-file-type-pdf'
}
]
},
{
label: 'Отчёты',
icon: 'i-bx24-outline-folder',
children: [
{
label: 'Квартал',
icon: 'i-bx24-outline-folder',
children: [
{
label: 'План продаж.xlsx',
icon: 'i-bx24-file-type-xls'
},
{
label: 'Презентация.pptx',
icon: 'i-bx24-file-type-pptx'
}
]
}
]
}
]
},
{
label: 'Регламент.docx',
icon: 'i-bx24-file-type-docx'
},
{
label: 'Логотип.png',
icon: 'i-bx24-file-type-img'
}
])
</script>
<template>
<B24Tree disabled :items="items" />
</template>
item.disabled.Примеры
Управление выбором
Выбранный элемент (или элементы) задают пропсом default-value или директивой v-model.
get-key задаёт функцию, которая получает уникальный ключ элемента, когда передан v-model или default-value.Чтобы элемент нельзя было выбрать, используйте свойство item.onSelect() или общее событие select:
Управление раскрытием
Раскрытые ветки задают пропсом default-expanded или директивой v-model:expanded.
Чтобы ветку нельзя было раскрыть, используйте свойство item.onToggle() или общее событие toggle:
С флажками
Слот item-leading позволяет поставить у элементов Checkbox. Пропсы multiple, propagate-select и bubble-select включают выбор с учётом родителей и потомков, а события select и toggle управляют выбором и раскрытием.
- Отдел продаж/
- Договоры/
- Отчёты/
- План продаж.xlsx
- Презентация.pptx
- Регламент.docx
- Логотип.png
as меняет элементы с button на div, потому что Checkbox тоже отрисовывается как button.Перетаскивание
Композабл useSortable из @vueuse/integrations включает перетаскивание элементов дерева. Он работает поверх Sortable.js.
nested: false: элементы стоят одним плоским списком, и их можно перетаскивать.Виртуализация
Пропс virtualize включает виртуализацию для длинных списков — true или объект с настройками, например { estimateSize: 32, overscan: 12 }.
nested: false.Свой слот
Свойство slot позволяет оформить отдельный элемент по-своему.
Доступны слоты:
#{{ item.slot }}-wrapper#{{ item.slot }}#{{ item.slot }}-leading#{{ item.slot }}-label#{{ item.slot }}-trailing
API
Пропсы
Слоты
События
Тема
Timeline
Компонент для хронологической последовательности событий с датами, заголовками и вспомогательными иконками или аватарами.
User
Компонент для показа данных пользователя: имени, описания и фото профиля.
Была ли страница полезна?