Tree 树形组件

用来展示树形结构的数据,具有展开关闭等功能

Tree 示例

>{}
<template>
  <div>
    <Row>
      <Col span="4">
        <Tree checked :data="the.tree.list" @onEvent="onTreeEvent" />
      </Col>
      <Col span="20">
        <div>{{ the.tree.onItem.id }}{{ the.tree.onItem.title }}</div>
      </Col>
    </Row>
  </div>
</template>

<script>
export default {
  setup() {
    // 使用外挂方式引入,具体查看demo
    const $plus = window.$plus;
    const { reactive } = $plus.vue;
    const { bll } = $plus.quick;

    const the = reactive({
      tree: {
        // 当前点击节点
        onItem: {},
        // 勾选数组
        onChecks: [],
        // 节点数据列表
        list: [
          {
            title: '组织',
            id: 1,
          },
          {
            title: '角色',
            id: 2,
            children: [
              {
                id: 21,
                title: '人民',
              },
              {
                id: 22,
                title: '群众',
              },
            ],
          },
        ],
      },
    });

    /** 树点击事件 */
    const onTreeEvent = (resp) => {
      console.log('onTreeEvent', resp.item);
      switch (resp.cmd) {
        case 'open':
          getTree(resp.bind, resp.item);
          break;
        case 'click':
          the.tree.onItem = resp.item;
          break;
        case 'check':
          //勾选
          if (resp.checked) {
            // 添加新的
            the.tree.onChecks.push(resp.value);
          } else {
            // 取消勾选
            bll.array.del(the.tree.onChecks, resp.value);
          }
          console.log('onTreeEvent.check', resp);
          break;
      }
    };

    return { the, onTreeEvent };
  },
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

Tree Props

属性说明类型默认值
theme默认黑暗主题Stringqv-tree-dark
active自定义激活节点String-
data绑定的数据Array-
checked是否启用勾选Booleanfalse
primary绑定勾选取值的字段Stringid

Tree data 绑定的数据

属性说明类型默认值
id节点勾选绑定值String
title节点描述String-
children子节点Array-

Tree events

事件名说明返回值
onEvent点击触发回调事件json

Events cmd open

  • 展开子项触发返回
参数名说明类型
active当前层级String
item当前选中的项Object

Last Updated: