1.0.8 • Published 1 month ago

@tanzhenxing/zx-tree v1.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

zx-tree 组件

基于 uni-app 的通用树形控件,支持 H5、小程序、App。参考 Element Plus Tree 设计,支持基础树、可选中、懒加载、自定义节点内容等功能。

功能特性

  • 支持多层级树形结构展示
  • 支持节点点击事件
  • 支持复选框选择(多选)
  • 支持懒加载子节点
  • 支持自定义节点内容
  • 兼容 H5、小程序、App(不依赖浏览器特有 DOM)

基本用法

<template>
  <zx-tree :data="treeData" @node-click="onNodeClick" />
</template>

<script setup>
import { ref } from 'vue'
import zxTree from '@/components/zx-tree/zx-tree.vue'

const treeData = ref([
  { id: 1, label: '一级 1', children: [ { id: 11, label: '二级 1-1' } ] },
  { id: 2, label: '一级 2' }
])
function onNodeClick(node) {
  console.log('点击节点', node)
}
</script>

属性说明

属性名说明类型默认值
data树形数据Array[]
props字段映射配置Object{ label, ... }
showCheckbox是否显示复选框Booleanfalse
lazy是否懒加载Booleanfalse
load懒加载方法Functionnull
defaultCheckedKeys默认选中节点 key 数组Array[]
isLeaf判断叶子节点方法Functionnull
renderContent自定义节点内容渲染Functionnull

props 字段默认值

{
  label: 'label',
  children: 'children',
  isLeaf: 'isLeaf',
  disabled: 'disabled',
  key: 'id',
}

事件说明

事件名说明回调参数
node-click节点被点击时触发(node)
check-change复选框选中状态变化(node, checked, indeterminate)
check复选框点击后触发(node, checkedKeys)

懒加载用法

<zx-tree :data="lazyTreeData" :lazy="true" :load="loadNode" />
<script setup>
const lazyTreeData = ref([
  { id: 1, label: '根节点1', isLeaf: false },
])
function loadNode(node, resolve) {
  setTimeout(() => {
    resolve([
      { id: 11, label: '子节点1-1', isLeaf: true },
    ])
  }, 800)
}
</script>

自定义节点内容

<zx-tree :data="treeData" :renderContent="renderNodeContent" />
<script setup>
function renderNodeContent({ node, level }) {
  return `<text style='color: #409EFF;'>${node.label}</text>`
}
</script>

兼容性说明

  • 组件未使用任何浏览器特有 DOM API,适配 uni-app 全端。

示例效果

请参考 src/pages/components/tree/index.vue 示例页面。

参考文档

1.0.8

1 month ago

1.0.7

1 month ago

1.0.6

2 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago