2.0.3 • Published 5 months ago

@wu-component/wu-tree-v2 v2.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Tree-v2 树组件

基础用法

用清晰的层级结构展示信息,可展开或折叠。

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: center;padding: 16px">
        <wu-plus-tree-v2 draggable="false" show-checkbox="false" data='[{"label":"一级 1","value":"1","children":[{"label":"二级 1-1","value":"1.1","children":[{"label":"三级 1-1-1","value":"1.1.1"}]}]},{"label":"一级 2","value":"2","children":[{"label":"二级 2-1","value":"2.1","children":[{"label":"三级 2-1-1","value":"2.1.1"}]},{"label":"二级 2-2","value":"2.2","children":[{"label":"三级 2-2-1","value":"2.2.1"}]}]},{"label":"一级 3","value":"3","children":[{"label":"二级 3-1","value":"3.1","children":[{"label":"三级 3-1-1","value":"3.1.1"}]},{"label":"二级 3-2","value":"3.2","children":[{"label":"三级 3-2-1","value":"3.2.1"}]}]}]'></wu-plus-tree-v2>
    </div>
</template>
<script>
</script>

:::

多节点选择

适用于需要选择层级时使用。

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: center;padding: 16px">
        <wu-plus-tree-v2 draggable="false" show-checkbox="true" data='[{"label":"一级 1","value":"1","children":[{"label":"二级 1-1","value":"1.1","children":[{"label":"三级 1-1-1","value":"1.1.1"}]}]},{"label":"一级 2","value":"2","children":[{"label":"二级 2-1","value":"2.1","children":[{"label":"三级 2-1-1","value":"2.1.1"}]},{"label":"二级 2-2","value":"2.2","children":[{"label":"三级 2-2-1","value":"2.2.1"}]}]},{"label":"一级 3","value":"3","children":[{"label":"二级 3-1","value":"3.1","children":[{"label":"三级 3-1-1","value":"3.1.1"}]},{"label":"二级 3-2","value":"3.2","children":[{"label":"三级 3-2-1","value":"3.2.1"}]}]}]'></wu-plus-tree-v2>
    </div>
</template>
<script>
</script>

:::

默认选中

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: center;padding: 16px">
        <wu-plus-tree-v2 draggable="false" show-checkbox="true" node-key="value" id="tree1" default-checked-keys="['1']" data='[{"label":"一级 1","value":"1","children":[{"label":"二级 1-1","value":"1.1","children":[{"label":"三级 1-1-1","value":"1.1.1"}]}]},{"label":"一级 2","value":"2","children":[{"label":"二级 2-1","value":"2.1","children":[{"label":"三级 2-1-1","value":"2.1.1"}]},{"label":"二级 2-2","value":"2.2","children":[{"label":"三级 2-2-1","value":"2.2.1"}]}]},{"label":"一级 3","value":"3","children":[{"label":"二级 3-1","value":"3.1","children":[{"label":"三级 3-1-1","value":"3.1.1"}]},{"label":"二级 3-2","value":"3.2","children":[{"label":"三级 3-2-1","value":"3.2.1"}]}]}]'></wu-plus-tree-v2>
    </div>
</template>
<script>
</script>

:::

默认展开

可将 Tree 的某些节点设置为默认展开子节点。

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: center;padding: 16px">
        <wu-plus-tree-v2 draggable="false" default-expanded-keys="['1', '1.1']" show-checkbox="true" node-key="value" id="tree1" default-checked-keys="['1']" data='[{"label":"一级 1","value":"1","children":[{"label":"二级 1-1","value":"1.1","children":[{"label":"三级 1-1-1","value":"1.1.1"}]}]},{"label":"一级 2","value":"2","children":[{"label":"二级 2-1","value":"2.1","children":[{"label":"三级 2-1-1","value":"2.1.1"}]},{"label":"二级 2-2","value":"2.2","children":[{"label":"三级 2-2-1","value":"2.2.1"}]}]},{"label":"一级 3","value":"3","children":[{"label":"二级 3-1","value":"3.1","children":[{"label":"三级 3-1-1","value":"3.1.1"}]},{"label":"二级 3-2","value":"3.2","children":[{"label":"三级 3-2-1","value":"3.2.1"}]}]}]'></wu-plus-tree-v2>
    </div>
</template>
<script>
</script>

:::

节点高亮

highlight-current 属性可以取消节点的选中高亮。

::: demo

<template>
    <div style="display: flex; align-items: center;justify-content: center;padding: 16px">
        <wu-plus-tree-v2 draggable="false"  highlight-current="false" show-checkbox="true" node-key="value" id="tree1" data='[{"label":"一级 1","value":"1","children":[{"label":"二级 1-1","value":"1.1","children":[{"label":"三级 1-1-1","value":"1.1.1"}]}]},{"label":"一级 2","value":"2","children":[{"label":"二级 2-1","value":"2.1","children":[{"label":"三级 2-1-1","value":"2.1.1"}]},{"label":"二级 2-2","value":"2.2","children":[{"label":"三级 2-2-1","value":"2.2.1"}]}]},{"label":"一级 3","value":"3","children":[{"label":"二级 3-1","value":"3.1","children":[{"label":"三级 3-1-1","value":"3.1.1"}]},{"label":"二级 3-2","value":"3.2","children":[{"label":"三级 3-2-1","value":"3.2.1"}]}]}]'></wu-plus-tree-v2>
    </div>
</template>
<script>
</script>

:::

Attributes

参数说明类型可选值默认值
data树数据Array--[]
highlight-current是否高亮Booleanfalse、truetrue
default-expand-all是否默认展开所有节点Booleanfalse、truefalse
expand-on-click-node是否在点击节点的时候展开或者收缩节点, 默认值为 true, 如果为 false,则只有点箭头图标的时候才会展开或者收缩节点。Booleanfalse、truetrue
check-on-click-node是否在点击节点的时候选中节点,默认值为 false,即只有在点击复选框时才会选中节点。Booleanfalse、truefalse
default-checked-keys默认选中的节点 keyArray--[]
auto-expand-parent展开子节点的时候是否自动展开父节点Booleanfalse、truetrue
default-expanded-keys默认展开的节点的 key 的数组Array--[]
show-checkbox节点是否可被选择Booleanfalse、truefalse
indent相邻级节点间的水平缩进,单位为像素Number--18
node-key每个树节点用来作为唯一标识的属性,整棵树应该是唯一的String----
node-key每个树节点用来作为唯一标识的属性,整棵树应该是唯一的String----
empty-text内容为空的时候展示的文本String----

Options

事件名说明参数
label指定节点标签为节点对象的某个属性值String
children指定子树为节点对象的某个属性值String
disabled指定节点选择框是否禁用为节点对象的某个属性值String
isLeaf指定节点是否为叶子节点,仅在指定了 lazy 属性的情况下生效String

Event

事件名说明参数
node-click节点点击(event: CustomEvent) => void
check-change节点勾选(event: CustomEvent) => void
current-change当前选中节点变化时触发的事件(event: CustomEvent) => void
node-expand节点被展开时触发的事件(event: CustomEvent) => void
node-collapse节点被关闭时触发的事件(event: CustomEvent) => void

Methods

事件名说明
getCurrentNode()获取当前被选中节点的 data,若没有节点被选中则返回 null
setCurrentNode()通过 node 设置某个节点的当前选中状态, 使用此方法必须设置 node-key 属性((node) 待被选节点的 node)
setCurrentKey()通过 key 设置某个节点的当前选中状态,使用此方法必须设置
node-key属性((key) 待被选节点的 key,若为 null 则取消当前高亮的节点)
getNode()根据 data 或者 key 拿到 Tree 组件中的 node
getCheckedNodes()若节点可被选择(即 show-checkbox 为 true), 则返回目前被选中的节点所组成的数组
setCheckedNodes()设置目前勾选的节点,使用此方法必须设置 node-key 属性
getCheckedKeys()若节点可被选择(即 show-checkbox 为 true), 则返回目前被选中的节点的 key 所组成的数组
getCurrentNode()获取当前被选中节点的 data,若没有节点被选中则返回 null

DataOptions

interface DataOptions {
    value: string;
    label: string;
    disabled: string;
}
2.0.3

5 months ago

2.0.1

1 year ago

2.0.0

1 year ago

1.11.8

1 year ago

1.11.6

1 year ago

1.11.4

1 year ago

1.9.24

2 years ago

1.9.21

2 years ago

1.9.20

2 years ago

1.9.17

2 years ago

1.9.2

2 years ago

1.9.1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago