Tree 树形控件 用清晰的层级结构展示信息,可展开或折叠。
基础用法 基础的树形结构展示
Level one 1Level one 2Level one 3vue
style="max-width: 600px" :data="data" :props="defaultProps" @node-click="handleNodeClick" /> interface Tree { label: string children?: Tree[] } const handleNodeClick = (data: Tree) => { console.log(data) } const data: Tree[] = [ { label: 'Level one 1', children: [ { label: 'Level two 1-1', children: [ { label: 'Level three 1-1-1', }, ], }, ], }, { label: 'Level one 2', children: [ { label: 'Level two 2-1', children: [ { label: 'Level three 2-1-1', }, ], }, { label: 'Level two 2-2', children: [ { label: 'Level three 2-2-1', }, ], }, ], }, { label: 'Level one 3', children: [ { label: 'Level two 3-1', children: [ { label: 'Level three 3-1-1', }, ], }, { label: 'Level two 3-2', children: [ { label: 'Level three 3-2-1', }, ], }, ], }, ] const defaultProps = { children: 'children', label: 'label', } 隐藏源代码可选择 适用于需要选择层级时使用。 本例还展示了动态加载节点数据的方法。 Root1Root2vue style="max-width: 600px" :props="props" :load="loadNode" lazy show-checkbox @check-change="handleCheckChange" /> import type { LoadFunction } from 'element-plus' interface Tree { name: string } let count = 1 const props = { label: 'name', children: 'zones', } const handleCheckChange = ( data: Tree, checked: boolean, indeterminate: boolean ) => { console.log(data, checked, indeterminate) } const loadNode: LoadFunction = (node, resolve) => { if (node.level === 0) { return resolve([{ name: 'Root1' }, { name: 'Root2' }]) } if (node.level > 3) return resolve([]) let hasChild = false if (node.data.name === 'region1') { hasChild = true } else if (node.data.name === 'region2') { hasChild = false } else { hasChild = Math.random() > 0.5 } setTimeout(() => { let data: Tree[] = [] if (hasChild) { data = [ { name: `zone${count++}`, }, { name: `zone${count++}`, }, ] } else { data = [] } resolve(data) }, 500) } 隐藏源代码WARNING 在使用 show-checkbox 时,因为 check-on-click-leaf 默认值为 true, 最后一个树节点可以通过点击节点进行勾选。 懒加载自定义叶子节点 由于在点击节点时才进行该层数据的获取,默认情况下 Tree 无法预知某个节点是否为叶子节点, 所以会为每个节点添加一个下拉按钮,如果节点没有下层数据,则点击后下拉按钮会消失。 同时,你也可以提前告知 Tree 某个节点是否为叶子节点,从而避免在叶子节点前渲染下拉按钮。 regionvue style="max-width: 600px" :props="props" :load="loadNode" lazy show-checkbox /> import type { LoadFunction } from 'element-plus' interface Tree { name: string leaf?: boolean } const props = { label: 'name', children: 'zones', isLeaf: 'leaf', } const loadNode: LoadFunction = (node, resolve) => { if (node.level === 0) { return resolve([{ name: 'region' }]) } if (node.level > 1) return resolve([]) setTimeout(() => { const data: Tree[] = [ { name: 'leaf', leaf: true, }, { name: 'zone', }, ] resolve(data) }, 500) } 隐藏源代码多次懒加载 2.6.3 加载远程节点数据时,懒加载有时可能失败。 在这种情况下,您可以调用 reject 以保持节点状态,并允许远程加载继续。 regionvue import type { LoadFunction } from 'element-plus' const props = { label: 'name', children: 'zones', isLeaf: 'leaf', } let time = 0 const loadNode: LoadFunction = (node, resolve, reject) => { if (node.level === 0) { return resolve([{ name: 'region' }]) } time++ if (node.level >= 1) { setTimeout(() => { if (time > 3) { return resolve([ { name: 'zone1', leaf: true }, { name: 'zone2', leaf: true }, { name: 'zone3', leaf: true }, ]) } else { return reject() } }, 3000) } } 隐藏源代码禁用复选框 节点的复选框可以设置为禁用。 在示例中,通过 disabled 设置禁用状态。 相应的复选框已禁用,不能点击。 Level one 1vue style="max-width: 600px" :data="data" :props="defaultProps" show-checkbox /> const defaultProps = { children: 'children', label: 'label', disabled: 'disabled', } const data = [ { id: 1, label: 'Level one 1', children: [ { id: 3, label: 'Level two 2-1', children: [ { id: 4, label: 'Level three 3-1-1', }, { id: 5, label: 'Level three 3-1-2', disabled: true, }, ], }, { id: 2, label: 'Level two 2-2', disabled: true, children: [ { id: 6, label: 'Level three 3-2-1', }, { id: 7, label: 'Level three 3-2-2', disabled: true, }, ], }, ], }, ] 隐藏源代码默认展开以及默认选中 树节点可以在初始化阶段被设置为展开和选中。 分别通过 default-expanded-keys 和 default-checked-keys 设置默认展开和默认选中的节点。 需要注意的是,此时必须设置 node-key, 其值为节点数据中的一个字段名,该字段在整棵树中是唯一的。 Level one 1Level one 2Level two 2-1Level two 2-2Level one 3Level two 3-1Level two 3-2vue style="max-width: 600px" :data="data" show-checkbox node-key="id" :default-expanded-keys="[2, 3]" :default-checked-keys="[5]" :props="defaultProps" /> const defaultProps = { children: 'children', label: 'label', } const data = [ { id: 1, label: 'Level one 1', children: [ { id: 4, label: 'Level two 1-1', children: [ { id: 9, label: 'Level three 1-1-1', }, { id: 10, label: 'Level three 1-1-2', }, ], }, ], }, { id: 2, label: 'Level one 2', children: [ { id: 5, label: 'Level two 2-1', }, { id: 6, label: 'Level two 2-2', }, ], }, { id: 3, label: 'Level one 3', children: [ { id: 7, label: 'Level two 3-1', }, { id: 8, label: 'Level two 3-2', }, ], }, ] 隐藏源代码树节点的选择 本例展示如何获取和设置选中节点。 获取和设置各有两种方式:通过 node 或通过 key。 如果需要通过 key 来获取或设置,则必须设置 node-key。 Level one 1Level two 1-1Level three 1-1-1Level three 1-1-2Level one 2Level two 2-1Level two 2-2Level one 3Level two 3-1Level two 3-2get by nodeget by keyset by nodeset by keyresetvue ref="treeRef" style="max-width: 600px" :data="data" show-checkbox default-expand-all node-key="id" highlight-current :props="defaultProps" /> import { ref } from 'vue' import type { RenderContentContext, TreeInstance } from 'element-plus' interface Tree { id: number label: string children?: Tree[] } type Node = RenderContentContext['node'] const treeRef = ref const getCheckedNodes = () => { console.log(treeRef.value!.getCheckedNodes(false, false)) } const getCheckedKeys = () => { console.log(treeRef.value!.getCheckedKeys(false)) } const setCheckedNodes = () => { treeRef.value!.setCheckedNodes( [ { id: 5, label: 'Level two 2-1', }, { id: 9, label: 'Level three 1-1-1', }, ] as Node[], false ) } const setCheckedKeys = () => { treeRef.value!.setCheckedKeys([3], false) } const resetChecked = () => { treeRef.value!.setCheckedKeys([], false) } const defaultProps = { children: 'children', label: 'label', } const data: Tree[] = [ { id: 1, label: 'Level one 1', children: [ { id: 4, label: 'Level two 1-1', children: [ { id: 9, label: 'Level three 1-1-1', }, { id: 10, label: 'Level three 1-1-2', }, ], }, ], }, { id: 2, label: 'Level one 2', children: [ { id: 5, label: 'Level two 2-1', }, { id: 6, label: 'Level two 2-2', }, ], }, { id: 3, label: 'Level one 3', children: [ { id: 7, label: 'Level two 3-1', }, { id: 8, label: 'Level two 3-2', }, ], }, ] 隐藏源代码自定义节点内容 节点的内容支持自定义,可以在节点区添加按钮或图标等内容 可以通过两种方法进行树节点内容的自定义:render-content 和 scoped slot。 使用 render-content 指定渲染函数,该函数返回需要的节点区内容即可。 渲染函数的用法请参考 Vue 文档。 使用 scoped slot 会传入两个参数 node 和 data,分别表示当前节点的 Node 对象和当前节点的数据。 注意:由于 JSFiddle 不支持 JSX 语法,所以 render-content 示例无法在那里运行。 但是在实际的项目中,只要正确地配置了相关依赖,就可以正常运行。 Using render-content Level one 1AppendDeleteLevel two 1-1AppendDeleteLevel three 1-1-1AppendDeleteLevel three 1-1-2AppendDeleteLevel one 2AppendDeleteLevel two 2-1AppendDeleteLevel two 2-2AppendDeleteLevel one 3AppendDeleteLevel two 3-1AppendDeleteLevel two 3-2AppendDeleteUsing scoped slot Level one 1 Append Delete Level two 1-1 Append Delete Level three 1-1-1 Append Delete Level three 1-1-2 Append Delete Level one 2 Append Delete Level two 2-1 Append Delete Level two 2-2 Append Delete Level one 3 Append Delete Level two 3-1 Append Delete Level two 3-2 Append Delete vue Using render-content ref="treeRef1" style="max-width: 600px" :data="dataSource" show-checkbox node-key="id" default-expand-all :expand-on-click-node="false" :render-content="renderContent" /> Using scoped slot ref="treeRef2" style="max-width: 600px" :data="dataSource" show-checkbox node-key="id" default-expand-all :expand-on-click-node="false" > {{ node.label }} Append style="margin-left: 4px" type="danger" link @click="remove(node, data)" > Delete import { ref } from 'vue' import { ElButton } from 'element-plus' import type { RenderContentContext, RenderContentFunction, TreeInstance, } from 'element-plus' interface Tree { id: number label: string children?: Tree[] } type Node = RenderContentContext['node'] type Data = RenderContentContext['data'] let id = 1000 const treeRef1 = ref const treeRef2 = ref const append = (data: Data) => { const newChild = { id: id++, label: 'testtest', children: [] } treeRef1.value?.append(newChild, data) treeRef2.value?.append(newChild, data) } const remove = (node: Node, data: Data) => { treeRef1.value?.remove(data) treeRef2.value?.remove(data) } const renderContent: RenderContentFunction = (h, { node, data }) => { return h( 'div', { class: 'custom-tree-node', }, [ h('span', null, node.label), h('div', null, [ h( ElButton, { type: 'primary', link: true, onClick: () => append(data), }, { default: () => 'Append', } ), h( ElButton, { type: 'danger', link: true, style: 'margin-left: 4px', onClick: () => remove(node, data), }, { default: () => 'Delete', } ), ]), ] ) } const dataSource = ref { id: 1, label: 'Level one 1', children: [ { id: 4, label: 'Level two 1-1', children: [ { id: 9, label: 'Level three 1-1-1', }, { id: 10, label: 'Level three 1-1-2', }, ], }, ], }, { id: 2, label: 'Level one 2', children: [ { id: 5, label: 'Level two 2-1', }, { id: 6, label: 'Level two 2-2', }, ], }, { id: 3, label: 'Level one 3', children: [ { id: 7, label: 'Level two 3-1', }, { id: 8, label: 'Level two 3-2', }, ], }, ]) .custom-tree-node { flex: 1; display: flex; align-items: center; justify-content: space-between; font-size: 14px; padding-right: 8px; } 隐藏源代码自定义节点类名 节点的类名支持自定义。 使用 props.class 来建立节点的类名。 Level one 1Level two 1-1Level three 1-1-1Level three 1-1-2Level one 2Level two 2-1Level two 2-2Level one 3Level two 3-1Level two 3-2vue style="max-width: 600px" :data="data" show-checkbox node-key="id" default-expand-all :expand-on-click-node="false" :props="{ class: customNodeClass }" /> import type { TreeNodeData } from 'element-plus' interface Tree { id: number label: string isPenultimate?: boolean children?: Tree[] } const customNodeClass = ({ isPenultimate }: TreeNodeData) => isPenultimate ? 'is-penultimate' : '' const data: Tree[] = [ { id: 1, label: 'Level one 1', children: [ { id: 4, label: 'Level two 1-1', isPenultimate: true, children: [ { id: 9, label: 'Level three 1-1-1', }, { id: 10, label: 'Level three 1-1-2', }, ], }, ], }, { id: 2, label: 'Level one 2', isPenultimate: true, children: [ { id: 5, label: 'Level two 2-1', }, { id: 6, label: 'Level two 2-2', }, ], }, { id: 3, label: 'Level one 3', isPenultimate: true, children: [ { id: 7, label: 'Level two 3-1', }, { id: 8, label: 'Level two 3-2', }, ], }, ] .is-penultimate > .el-tree-node__content { color: #626aef; } .is-penultimate > .el-tree-node__children > div { display: inline-block; margin-right: 4px; &:not(:first-child) .el-tree-node__content { padding-left: 0px !important; } .el-tree-node__content { padding-right: 16px; } } 隐藏源代码树节点过滤 树节点是可以被过滤的 调用 Tree 实例对象的 filter 方法来过滤树节点。 方法的参数就是过滤关键字。 需要注意的是,此时需要设置 filter-node-method 属性,其值为过滤函数。 Level one 1Level two 1-1Level three 1-1-1Level three 1-1-2Level one 2Level two 2-1Level two 2-2Level one 3Level two 3-1Level two 3-2vue v-model="filterText" class="w-60 mb-2" placeholder="Filter keyword" /> ref="treeRef" style="max-width: 600px" class="filter-tree" :data="data" :props="defaultProps" default-expand-all :filter-node-method="filterNode" /> import { ref, watch } from 'vue' import type { FilterNodeMethodFunction, TreeInstance } from 'element-plus' interface Tree { [key: string]: any } const filterText = ref('') const treeRef = ref const defaultProps = { children: 'children', label: 'label', } watch(filterText, (val) => { treeRef.value!.filter(val) }) const filterNode: FilterNodeMethodFunction = (value: string, data: Tree) => { if (!value) return true return data.label.includes(value) } const data: Tree[] = [ { id: 1, label: 'Level one 1', children: [ { id: 4, label: 'Level two 1-1', children: [ { id: 9, label: 'Level three 1-1-1', }, { id: 10, label: 'Level three 1-1-2', }, ], }, ], }, { id: 2, label: 'Level one 2', children: [ { id: 5, label: 'Level two 2-1', }, { id: 6, label: 'Level two 2-2', }, ], }, { id: 3, label: 'Level one 3', children: [ { id: 7, label: 'Level two 3-1', }, { id: 8, label: 'Level two 3-2', }, ], }, ] 隐藏源代码手风琴模式 对于同一级的节点,每次只能展开一个 Level one 1Level one 2Level one 3vue style="max-width: 600px" :data="data" :props="defaultProps" accordion @node-click="handleNodeClick" /> interface Tree { label: string children?: Tree[] } const handleNodeClick = (data: Tree) => { console.log(data) } const data: Tree[] = [ { label: 'Level one 1', children: [ { label: 'Level two 1-1', children: [ { label: 'Level three 1-1-1', }, ], }, ], }, { label: 'Level one 2', children: [ { label: 'Level two 2-1', children: [ { label: 'Level three 2-1-1', }, ], }, { label: 'Level two 2-2', children: [ { label: 'Level three 2-2-1', }, ], }, ], }, { label: 'Level one 3', children: [ { label: 'Level two 3-1', children: [ { label: 'Level three 3-1-1', }, ], }, { label: 'Level two 3-2', children: [ { label: 'Level three 3-2-1', }, ], }, ], }, ] const defaultProps = { children: 'children', label: 'label', } 隐藏源代码可拖拽节点 通过 draggable 属性可让节点变为可拖拽 Level one 1Level two 1-1Level three 1-1-1Level one 2Level two 2-1Level three 2-1-1Level two 2-2Level three 2-2-1Level one 3Level two 3-1Level three 3-1-1Level two 3-2Level three 3-2-1vue style="max-width: 600px" :allow-drop="allowDrop" :allow-drag="allowDrag" :data="data" draggable default-expand-all node-key="id" @node-drag-start="handleDragStart" @node-drag-enter="handleDragEnter" @node-drag-leave="handleDragLeave" @node-drag-over="handleDragOver" @node-drag-end="handleDragEnd" @node-drop="handleDrop" /> import type { AllowDropType, NodeDropType, RenderContentContext, } from 'element-plus' type Node = RenderContentContext['node'] const handleDragStart = (node: Node, ev: DragEvent) => { console.log('drag start', node) } const handleDragEnter = (draggingNode: Node, dropNode: Node, ev: DragEvent) => { console.log('tree drag enter:', dropNode.label) } const handleDragLeave = (draggingNode: Node, dropNode: Node, ev: DragEvent) => { console.log('tree drag leave:', dropNode.label) } const handleDragOver = (draggingNode: Node, dropNode: Node, ev: DragEvent) => { console.log('tree drag over:', dropNode.label) } const handleDragEnd = ( draggingNode: Node, dropNode: Node | null, dropType: NodeDropType, ev: DragEvent ) => { console.log('tree drag end:', dropNode && dropNode.label, dropType) } const handleDrop = ( draggingNode: Node, dropNode: Node, dropType: Exclude ev: DragEvent ) => { console.log('tree drop:', dropNode.label, dropType) } const allowDrop = (draggingNode: Node, dropNode: Node, type: AllowDropType) => { if (dropNode.data.label === 'Level two 3-1') { return type !== 'inner' } else { return true } } const allowDrag = (draggingNode: Node) => { return !draggingNode.data.label.includes('Level three 3-1-1') } const data = [ { label: 'Level one 1', children: [ { label: 'Level two 1-1', children: [ { label: 'Level three 1-1-1', }, ], }, ], }, { label: 'Level one 2', children: [ { label: 'Level two 2-1', children: [ { label: 'Level three 2-1-1', }, ], }, { label: 'Level two 2-2', children: [ { label: 'Level three 2-2-1', }, ], }, ], }, { label: 'Level one 3', children: [ { label: 'Level two 3-1', children: [ { label: 'Level three 3-1-1', }, ], }, { label: 'Level two 3-2', children: [ { label: 'Level three 3-2-1', }, ], }, ], }, ] 隐藏源代码Tree API 属性 属性名说明类型默认值data展示数据array—empty-text内容为空的时候展示的文本string—node-key每个树节点用来作为唯一标识的属性,整棵树应该是唯一的string—props配置选项,具体看下表object—render-after-expand是否在第一次展开某个树节点后才渲染其子节点booleantrueload加载子树数据的方法,仅当 lazy 属性为true 时生效Function—render-content树节点的内容区的渲染 FunctionFunction—highlight-current是否高亮当前选中节点,默认值是 false。booleanfalsedefault-expand-all是否默认展开所有节点booleanfalseexpand-on-click-node是否在点击节点的时候展开或者收缩节点, 默认值为 true,如果为 false,则只有点箭头图标的时候才会展开或者收缩节点。booleantruecheck-on-click-node是否在点击节点的时候选中节点,默认值为 false,即只有在点击复选框时才会选中节点。booleanfalsecheck-on-click-leaf 2.9.6点击叶节点(最后一个子节点)时是否选中或取消选中节点。booleantrueauto-expand-parent展开子节点的时候是否自动展开父节点booleantruedefault-expanded-keys默认展开的节点的 key 的数组array—show-checkbox节点是否可被选择booleanfalsecheck-strictly在显示复选框的情况下,是否严格的遵循父子不互相关联的做法,默认为 falsebooleanfalsedefault-checked-keys默认勾选的节点的 key 的数组array—current-node-key当前选中的节点string / number—filter-node-method对树节点进行筛选时执行的方法, 返回 false 则表示这个节点会被隐藏Function—accordion是否每次只打开一个同级树节点展开booleanfalseindent相邻级节点间的水平缩进,单位为像素number18icon自定义树节点图标组件string / Component—lazy是否懒加载子节点,需与 load 方法结合使用booleanfalsedraggable是否开启拖拽节点功能booleanfalseallow-drag判断节点能否被拖拽 如果返回 false ,节点不能被拖动Function—allow-drop拖拽时判定目标节点能否成为拖动目标位置。 如果返回 false ,拖动节点不能被拖放到目标节点。 type 参数有三种情况:'prev'、'inner' 和 'next',分别表示放置在目标节点前、插入至目标节点和放置在目标节点后Function—Props Props说明类型默认值label指定节点标签为节点对象的某个属性值string / Function—children指定子树为节点对象的某个属性值string—disabled指定节点选择框是否禁用为节点对象的某个属性值string / Function—isLeaf指定节点是否为叶子节点,仅在指定了 lazy 属性的情况下生效string / Function—class自定义节点类名string / Function—对外暴露的方法 Tree 组件有以下方法,均返回当前选中的节点数组 方法说明回调参数filter过滤所有树节点,过滤后的节点将被隐藏接收一个参数并指定为 filter-node-method 属性的第一个参数updateKeyChildren为节点设置新数据,只有当设置 node-key 属性的时候才可用(key, data) 接收两个参数: 1. 节点的 key 2. 新数据getCheckedNodes如果节点可以被选中,(show-checkbox 为 true), 本方法将返回当前选中节点的数组(leafOnly, includeHalfChecked) 接收两个布尔类型参数: 1. 默认值为 false. 若参数为 true, 它将返回当前选中节点的子节点 2. 默认值为 false. 如果参数为 true, 返回值包含半选中节点数据setCheckedNodes设置目前选中的节点,使用此方法必须设置 node-key 属性(nodes, leafOnly) 接收两个参数: 1. 要选中的节点对象构成的数组 2. 布尔类型的值 如果设置为 true,将只设置选中的叶子节点状态。 默认值是 false.getCheckedKeys若节点可用被选中 (show-checkbox 为 true), 它将返回当前选中节点 key 的数组(leafOnly) 接收一个布尔类型参数,默认为 false. 若参数为 true, 它将返回当前选中节点的子节点setCheckedKeys设置目前选中的节点,使用此方法必须设置 node-key 属性(keys, leafOnly) 接收两个参数: 1. 一个需要被选中的多节点 key 的数组 2. 布尔类型的值 如果设置为 true,将只设置选中的叶子节点状态。 默认值是 false.setChecked设置节点是否被选中, 使用此方法必须设置 node-key 属性(key/data, checked, deep) 接收三个参数: 1. 要选中的节点的 key 或者数据 2. 一个布尔类型参数表明是否选中. 3. 一个布尔类型的参数,用于指示是否为深层(deep)操作(注意:check-strictly 必须为 false)。getHalfCheckedNodes如果节点可用被选中 (show-checkbox 为 true), 它将返回当前半选中的节点组成的数组:::getHalfCheckedKeys若节点可被选中(show-checkbox 为 true),则返回目前半选中的节点的 key 所组成的数组:::getCurrentKey返回当前被选中节点的数据 (如果没有则返回 null):::getCurrentNode返回当前被选中节点的数据 (如果没有则返回 null):::setCurrentKey通过 key 设置某个节点的当前选中状态,使用此方法必须设置 node-key 属性(key, shouldAutoExpandParent=true) 1. 待被选节点的 key, 如果为 null, 取消当前选中的节点 2. 是否展开父节点setCurrentNode设置节点为选中状态,使用此方法必须设置 node-key 属性(node, shouldAutoExpandParent=true) 1. 待被选中的节点 2. 是否展开父节点getNode根据 data 或者 key 拿到 Tree 组件中的 node(data) 节点的 data 或 keyremove删除 Tree 中的一个节点,使用此方法必须设置 node-key 属性(data) 要删除的节点的 data 或者 node 对象append为 Tree 中的一个节点追加一个子节点(data, parentNode) 1. 要追加的子节点的 data 2. 父节点的 data, key 或 nodeinsertBefore在 Tree 中给定节点前插入一个节点(data, refNode) 1. 要增加的节点的 data 2. 参考节点的 data, key 或 nodeinsertAfter在 Tree 中给定节点后插入一个节点(data, refNode) 1. 要增加的节点的 data 2. 参考节点的 data, key 或 node事件 方法名说明类型node-click当节点被点击的时候触发四个参数:对应于节点点击的节点对象,TreeNode 的 node 属性, TreeNode和事件对象node-contextmenu当某一节点被鼠标右键点击时会触发该事件共四个参数,依次为:event、传递给 data 属性的数组中该节点所对应的对象、节点对应的 Node、节点组件本身。check-change当复选框被点击的时候触发共三个参数,依次为:传递给 data 属性的数组中该节点所对应的对象、节点本身是否被选中、节点的子树中是否有被选中的节点check点击节点复选框之后触发共两个参数,依次为:传递给 data 属性的数组中该节点所对应的对象、树目前的选中状态对象,包含 checkedNodes、checkedKeys、halfCheckedNodes、halfCheckedKeys 四个属性current-change当前选中节点变化时触发的事件共两个参数,依次为:当前节点的数据,当前节点的 Node 对象node-expand节点被展开时触发的事件共三个参数,依次为:传递给 data 属性的数组中该节点所对应的对象、节点对应的 Node、节点组件本身node-collapse节点被关闭时触发的事件共三个参数,依次为:传递给 data 属性的数组中该节点所对应的对象、节点对应的 Node、节点组件本身node-drag-start节点开始拖拽时触发的事件共两个参数,依次为:被拖拽节点对应的 Node、eventnode-drag-enter拖拽进入其他节点时触发的事件共三个参数,依次为:被拖拽节点对应的 Node、所进入节点对应的 Node、eventnode-drag-leave拖拽离开某个节点时触发的事件共三个参数,依次为:被拖拽节点对应的 Node、所离开节点对应的 Node、eventnode-drag-over在拖拽节点时触发的事件(类似浏览器的 mouseover 事件)共三个参数,依次为:被拖拽节点对应的 Node、当前进入节点对应的 Node、eventnode-drag-end拖拽结束时(可能未成功)触发的事件共四个参数,依次为:被拖拽节点对应的 Node、结束拖拽时最后进入的节点(可能为空)、被拖拽节点的放置位置(before、after、inner)、eventnode-drop拖拽成功完成时触发的事件共四个参数,依次为:被拖拽节点对应的 Node、结束拖拽时最后进入的节点、被拖拽节点的放置位置(before、after、inner)、event插槽 插槽名描述Typedefault自定义树节点的内容。objectempty 2.3.4当数据为空时自定义的内容:::类型声明 Show declarationstsinterface RootTreeType { root: Ref // ... } // UnwrapRef type Node = { canFocus: boolean checked: boolean childNodes: Node[] data: TreeNodeData expanded: boolean id: number indeterminate: boolean isCurrent: boolean isEffectivelyChecked: boolean isLeaf?: boolean isLeafByUser?: boolean level: number loaded: boolean loading: boolean parent: Node | null store: TreeStore text: string | null visible: boolean } // TreeNodeData => Tree / TreeOptionProps // Tree type is your prop type. // TreeOptionProps is default prop type interface TreeOptionProps { children?: string label?: string | ((data: TreeNodeData, node: Node) => string) disabled?: string | ((data: TreeNodeData, node: Node) => boolean) isLeaf?: string | ((data: TreeNodeData, node: Node) => boolean) class?: ( data: TreeNodeData, node: Node ) => string | { [key: string]: boolean } }源代码 组件 • 样式 • 文档 贡献者
友情链接:
Copyright © 2022 卡塔尔世界杯排名_98世界杯决赛 - dylfjc.com All Rights Reserved.