Tree

Reference

allow-open-disabledfalse
Boolean
If true disabled folders items can be opened

allow-select-disabledfalse
Boolean
If true disabled items can be selected

auto-open-allfalse
Boolean
If true mounts tree with all nodes open

auto-open-rootfalse
Boolean
If true mounts tree with the root node open

base"tree"
String
Base name used to style component

chevron
(attributes)
{}
Object
Attributes of the v-chevron (open indicator) component. See the documentation for the valid values

filterempty string
String
String used to filter items

item-children"children"
String
Name of the property that hold the name of array of children

item-disabled"disabled"
String
Name of the property for the disabled items. Disabling folder also disable all of its children

item-icon"icon"
String
Name of the property that hold the name of the item's icon. Valid name is the same as for the v-icon name prop

item-key"id"
String
Name of the required property that hold unique value for every item.

item-name"name"
String
Name of the property that hold the name of item

items[]
Object
Array of the tree items

mod-folderempty string
String
Style of the folder element

mod-iconempty string
String
Style of the icon element

mod-itemempty string
String
Style of the item element

nameempty string
String
Name of the component

open-on-clicktrue
Boolean
If true clicking on the label opens folder. Clicking an indicator always opens folders

placeholder-folder-iconundefined
StringObject
Default icon for the folders if no icon is provided in the items prop. If value is the array then the icons are respectively for the close and open folders

placeholder-item-iconundefined
StringObject
Default icon for the items if no icon is provided in the items prop

select-independentfalse
Boolean
If true folders and items can be selected independently. By default selecting a folder selects all of its children items and selecting every children selects the parent folder

select-return-keysfalse
Boolean
If true the input:selected event returns an array of item keys. If false (default) this event returns an array of the item objects

show-checkboxesfalse
Boolean
Displays checkboxes

show-iconstrue
Boolean
Displays icons if the icon or placeholder icon is set

show-indicatorstrue
Boolean
Displays open indicators

transition"fade"
String
Sets the animation effect when opening or closing folders. Valid values are: 'fade', 'fade-slide', or empty string to disable animations.

variantempty string
String
Active variant of the element mod-* props
Events
input:selected
Fired when an item is selected. Passes an array of the selected items

input:click
Fired when an item is clicked
Slots
item
Slot for the complete customization of appearance of the items. Other slots are unavailable when using this slot

icon
Slot for the items icon

item-prepend
Slot for the content that prepends item name

name
Slot for the items name

item-append
Slot for the content that is appended to the item name
Functions
openAllLevel(level: Number)
Opens all nodes on the level (0 for the root, any high number to open all nodes)

closeAll()
Closes all nodes

Example - simple tree

    <template>
  <v-tree :items="items"></v-tree>
</template>
  
    <script setup>
import { ref } from "vue";

const items = ref([
  {
    name: "Directory",
    id: 17,
    children: [
      { name: "Some item", id: 1 },
      { name: "Another item", id: 2 },
      { name: "Third", id: 3 },
      { name: "File" },
      {
        name: "Sub directory",
        id: 5,
        children: [
          {
            name: "Another sub directory",
            id: 6,
            children: [
              { name: "Content", id: 7 },
              { name: "Another item", id: 8 },
            ],
          },
          { name: "Fourth", id: 9 },
          { name: "Another file", id: 10 },
          { name: "Video file", id: 11 },
          { name: "Secret item", id: 12 },
          {
            name: "More content here",
            id: 13,
            children: [
              { name: "Another video file", id: 14 },
              { name: "Fifth", id: 15 },
            ],
          },
        ],
      },
      { name: "Sixth item", id: 16 },
    ],
  },
]);
</script>
  

Example - props and events

true
true
true
false
false
false
false
true
fade
    <template>
  <v-tree
    v-bind="example"
    ref="treeRef"
    :chevron="{ triangle: true }"
    :placeholder-folder-icon="['mdi-folder', 'mdi-folder-open']"
    placeholder-item-icon="b-file-earmark"
    @input:click="handleClickItem"
    @input:selected="handleSelectedItem"
  >
    <template #item-append="{ item }">
      <v-badge
        v-if="item.badge"
        mod-badge="size:tiny"
        class="ml-2"
      >
        {{ item.badge }}
      </v-badge>
    </template>
  </v-tree>

  <v-button
    mod-button="size:small"
    class="mr-4 mt-8"
    @click="treeRef.openAllLevel(9999)"
  >
    Open all
  </v-button>
  <v-button
    mod-button="size:small"
    @click="treeRef.closeAll()"
  >
    Close all
  </v-button>

</template>
  
    <script setup>
import { ref, reactive } from "vue";

const treeData = [
  {
    name: "Directory",
    id: 17,
    children: [
      { name: "Some item", id: 1 },
      { name: "Another item", id: 2 },
      { name: "Third item", id: 3 },
      { name: "File", icon: "b-star", id: 4 },
      {
        name: "Sub directory",
        id: 5,
        children: [
          {
            name: "Another sub directory",
            id: 6,
            children: [
              { name: "Content", id: 7 },
              { name: "Another item", id: 8 },
            ],
          },
          { name: "Fourth item", id: 9 },
          { name: "Another file", id: 10 },
          { name: "Video file", id: 11 },
          { name: "Secret item", id: 12 },
          {
            name: "More content here",
            id: 13,
            children: [
              { name: "Another video file", id: 14, badge: "NEW" },
              { name: "Fifth item", id: 15 },
            ],
          },
        ],
      },
      { name: "Sixth item", id: 16 },
    ],
  },
  {
    name: "Another directory",
    id: 17,
    children: [
      {
        name: "Sub dir",
        id: 5,
        children: [
          { name: "New file", id: 9 },
          { name: "Music file", id: 10 },
          { name: "Secret content", id: 12 },
          {
            name: "Folder",
            id: 13,
            children: [
              { name: "Another file", id: 14, badge: "NEW" },
              { name: "Readme", id: 15 },
            ],
          },
        ],
      },
      { name: "More content", id: 1 },
      { name: "Movie file", id: 16 },
    ],
  },
];

let example = reactive({
  items: treeData,
  openOnClick: true,
  showIndicators: true,
  showIcons: true,
  showCheckboxes: false,
  filter: "",
  openAll: false,
  autoOpenRoot: false,
  autoOpenAll: false,
  selectReturnKeys: false,
  selectIndependent: false,
  allowSelectDisabled: false,
  allowOpenDisabled: true,
  transition: "fade",
});

let treeRef = ref(null);

let events = ref([]);

let handleClickItem = (item) => {
  events.value.unshift({ ev: "input:click", data: item });
};

let handleSelectedItem = (selection) => {
  events.value.unshift({ ev: "input:selected", data: selection });
};
</script>