본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Tree

원문 보기 위키 갱신

Tree (트리)

Tree는 계층적 목록 구조를 표시하는 컴포넌트예요. 디렉토리, 조직도, 생물 분류, 국가 등 계층 관계를 나타내는 데 사용돼요.

출처: 문서

본문

언제 사용하나요

거의 모든 것이 트리 구조로 표현될 수 있어요. 예를 들어 디렉토리, 조직 계층, 생물 분류, 국가 등이 있죠. Tree 컴포넌트는 이들 사이의 계층 관계를 나타내는 방식이에요. Tree 안에서 treeNode를 펼치고(expand), 접고(collapse), 선택할 수도 있어요.

API

Tree props

속성 설명 타입 기본값 버전
allowDrop 노드에 드롭을 허용할지 여부예요 ({ dropNode, dropPosition }) => boolean -
autoExpandParent 부모 treeNode를 자동으로 펼칠지 여부예요 boolean false
blockNode treeNode가 남은 가로 공간을 채울지 여부예요 boolean false
checkable treeNode 앞에 Checkbox를 추가해요 boolean false
checkedKeys(v-model) (제어) 체크된 treeNode의 키를 지정해요. (참고: 부모 treeNode의 키를 지정하면 그 자식 treeNode들도 모두 체크되고, 반대로 자식 treeNode의 키를 지정하면 부모 treeNode도 체크돼요. checkable과 checkStrictly가 true일 때는 그 객체가 checked와 halfChecked 속성을 가져요. 자식 또는 부모 treeNode가 체크되었는지 여부는 서로에게 영향을 주지 않아요.) string[] | number[] | {checked: string[] | number[], halfChecked: string[] | number[]} []
checkStrictly treeNode를 정확히 체크해요. 부모 treeNode와 자식 treeNode가 서로 연관되지 않아요 boolean false
defaultExpandAll 기본적으로 모든 treeNode를 펼칠지 여부예요 boolean false
disabled 트리를 비활성화할지 여부예요 bool false
draggable 이 Tree가 드래그 가능한지 여부예요 (IE > 8) boolean false
expandedKeys(v-model) (제어) 펼쳐진 treeNode의 키를 지정해요 string[] | number[] []
fieldNames treeNode의 title, key, children 필드를 treeData의 해당 필드로 교체해요 object { children:'children', title:'title', key:'key' } 3.0.0
filterTreeNode treeNode를 필터(하이라이트)하는 함수를 정의해요. 함수가 true를 반환하면 해당 treeNode가 하이라이트돼요 function(node) -
height 가상 스크롤 높이를 설정해요. 활성화하면 가로 스크롤은 지원하지 않아요 number -
loadData 데이터를 비동기로 로드해요 function(node) -
loadedKeys (제어) 로드된 트리 노드를 설정해요. loadData와 함께 사용해야 해요 string[] | number[] []
multiple 여러 treeNode 선택을 허용해요 boolean false
selectable 선택 가능한지 여부예요 boolean true
selectedKeys(v-model) (제어) 선택된 treeNode의 키를 지정해요 string[] | number[] -
showIcon TreeNode 제목 앞에 아이콘을 표시해요. 기본 스타일은 없으므로 true로 설정하면 커스텀 스타일을 직접 지정해야 해요 boolean false
showLine 연결선을 표시해요 boolean | {showLeafIcon: boolean}(3.0+) false
switcherIcon 트리 노드의 접기/펼치기 아이콘을 커스터마이즈해요 v-slot:switcherIcon="{active, checked, expanded, loading, selected, halfChecked, title, key, children, dataRef, data, defaultIcon, switcherCls}" -
title 커스텀 제목이에요 slot 2.0.0
treeData 트리의 treeNode예요. v1.1.4 이전에는 treeNodes를 사용해주세요 TreeNode[] -
virtual false로 설정하면 가상 스크롤을 비활성화해요 boolean true 3.0

Events

이벤트 이름 설명 인자
check onCheck 이벤트가 발생했을 때의 콜백 함수예요 function(checkedKeys, e:{checked: bool, checkedNodes, node, event})
dragend onDragEnd 이벤트가 발생했을 때의 콜백 함수예요 function({event, node})
dragenter onDragEnter 이벤트가 발생했을 때의 콜백 함수예요 function({event, node, expandedKeys})
dragleave onDragLeave 이벤트가 발생했을 때의 콜백 함수예요 function({event, node})
dragover onDragOver 이벤트가 발생했을 때의 콜백 함수예요 function({event, node})
dragstart onDragStart 이벤트가 발생했을 때의 콜백 함수예요 function({event, node})
drop onDrop 이벤트가 발생했을 때의 콜백 함수예요 function({event, node, dragNode, dragNodesKeys})
expand treeNode가 펼쳐지거나 접힐 때의 콜백 함수예요 function(expandedKeys, {expanded: bool, node})
load treeNode가 로드될 때의 콜백 함수예요 function(loadedKeys, {event, node})
rightClick 사용자가 treeNode를 오른쪽 클릭했을 때의 콜백 함수예요 function({event, node})
select 사용자가 treeNode를 클릭했을 때의 콜백 함수예요 function(selectedKeys, e:{selected: bool, selectedNodes, node, event})

Tree Methods

이름 설명
scrollTo({ key: string | number; align?: 'top' | 'bottom' | 'auto'; offset?: number }) 가상 스크롤에서 key 항목으로 스크롤해요

TreeNode

속성 설명 타입 기본값 버전
checkable Tree가 checkable일 때 TreeNode에 Checkbox를 표시할지 여부예요 boolean -
class className이에요 string -
disableCheckbox treeNode의 체크박스를 비활성화해요 boolean false
disabled treeNode를 비활성화해요 boolean false
icon 아이콘을 커스터마이즈해요. 컴포넌트를 전달하면 그 렌더가 컴포넌트 props로 전체 TreeNode props를 받아요 slot|slot-scope -
isLeaf 리프(leaf) 노드인지 여부를 결정해요 (loadData가 지정된 경우 유효) boolean -
key (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys와 함께 사용해요. 참고: 트리의 모든 treeNode 중에서 반드시 고유해야 해요! string | number 트리 노드의 내부 계산 위치
selectable treeNode가 선택 가능한지 설정해요 boolean true
style style이에요 string|object -
title 제목이에요 string '---'

DirectoryTree props

속성 설명 타입 기본값
expandAction 디렉토리 열기 로직이에요. 옵션: false 'click' 'dblclick' string click

FAQ

showLine 사용 시 파일 아이콘을 숨기려면 어떻게 하나요?

파일 아이콘은 switcherIcon으로 구현돼요. 스타일을 덮어써서 숨길 수 있어요.

더 알아보기