Code Monkey home page Code Monkey logo

vue-tree's Introduction

Vue-Tree 3.x

一款高性能 vue 虚拟树控件,支持搜索,定位,拖拽等。该控件是在公司业务的基础上不断打磨出来的,提供了十分丰富强大的 API,几乎能够满足你对树控件的所有需求。该控件同时支持 vue2 以及 vue3。

这是原先ctree的升级版本,同时支持 vue2 和 vue3。 新版改变了包的名称和部分 export 模块名称。

案例

在线 demo

安装

yarn 安装方式

yarn add @wsfe/vue-tree

npm 安装方式

npm install @wsfe/vue-tree

样式引入

直接引入 css

@import '~@wsfe/vue-tree/style.css';

引入 less 以便于变量覆盖

@import '~@wsfe/vue-tree/src/styles/index.less';

使用方式

// 大家可以根据需要是否引入VTreeNode, VTreeSearch, VTreeDrop
import Vtree, { VTreeNode, VTreeSearch, VTreeDrop } from '@wsfe/vue-tree'
import '@wsfe/vue-tree/style.css'

接口文档

VTree API

VTree Props

属性 说明 类型 默认值
value 选中的值,可用 v-model ;单选为字符串或数字,多选为 separator 分隔的字符串或数组,优先多选 string | number | Array<string | number>
data 传入的树数据。数据量大时,不建议通过 props 传入数据,建议用 setData 方法代替 object[] []
unloadDataList 供未加载且选中节点查询 title 字段值用的列表,格式与 data 一致即可 object[] []
showUnloadCheckedNodes 过滤已选时是否在列表后面展示未加载的已选节点 boolean true
emptyText 数据为空时显示的文本 string '暂无数据'
titleField 节点标题字段 string 'title'
keyField 节点唯一标识字段 string 'id'
separator 多选模式下 value 分隔符 string ','
checkable 是否可多选 boolean false
selectable 是否可单选 boolean false
filteredNodeCheckable 是否可勾选被过滤节点 boolean false
cascade 父子节点是否关联 boolean true
enableLeafOnly 是否只启用子节点,当 多选且父子不关联单选 时有效 boolean false
disableAll 是否禁用所有节点 boolean false
defaultExpandAll 是否默认展开所有节点 boolean false
defaultExpandedKeys Deprecated 默认展开的节点 key Array<string | number> []
expandedKeys 2.2.0 展开的节点 key ,组件内部将会响应此 Prop 的变化 Array<string | number> []
draggable 是否可拖拽 boolean false
droppable 是否可放置 boolean false
beforeDropMethod 在放置节点之前执行的方法,返回 true 允许放置, false 可阻止放置 (dragKey: string | number, dropKey: string | number, hoverPart: 'before' | 'body' | 'after') => boolean () => true
ignoreMode 忽略模式,指定 getCheckedNodes, getCheckedKeysv-model 默认要忽略的部分 'none' | 'parents' | 'children' 'none'
autoLoad 异步加载初始化时是否自动加载根节点 boolean true
load 异步加载方法 (node: null | TreeNode, resolve: Function, reject: Function) => any
render 节点渲染 render 函数 (h: CreateElement, node: TreeNode) => VNode
filterMethod 节点过滤方法 (keyword: string, node: TreeNode) => boolean
expandOnFilter 2.1.0 过滤时是否展开所有可见节点 boolean true
unselectOnClick 2.1.0 点击已选中节点是否取消选中 boolean true
loading 是否显示 loading 图标 boolean false
nodeClassName 节点根元素的 class ,传入函数以对每个节点定制 class string | object | Array<string | object> | (node: TreeNode) => string | object | Array<string | object>
nodeMinHeight 根据节点最小高度计算数据总高度 number 30
nodeIndent 子节点缩进 number 20
renderNodeAmount 渲染节点数量,可见节点数大于此值且高度超过(容器可视高度能容纳节点数 + bufferNodeAmount)则不会渲染所有可见节点 number 100
bufferNodeAmount 当滚动到视野外的节点个数大于此值时刷新渲染节点 number 20

VTree Events

注:从 2.0.8 起,事件中返回的节点信息都是包括 _parentchildren 的完整节点信息(拖拽事件的 dataTransfer 除外)。

事件名 说明 返回值
input 选中节点改变时触发 选中的节点
expand 展开/折叠时触发 节点信息
check 勾选时触发(多选) 被勾选的节点信息
uncheck 取消勾选时触发(多选) 被取消勾选的节点信息
checked-change 勾选/取消勾选时触发(多选) 所有被勾选节点(数组)
select 选中时触发(单选) 被选中的节点信息
unselect 取消选中时触发(单选) 被取消选中的节点信息
selected-change 选中/取消选中时触发(单选) 被选中节点
click 点击节点时触发 节点信息, 鼠标事件
node-dblclick 双击节点时触发 节点信息, 鼠标事件
node-right-click 右击节点时触发 节点信息, 鼠标事件
node-dragstart 开始拖拽节点时触发 节点信息, 拖拽事件对象
node-dragenter dragenter 时触发 节点信息 , 拖拽事件对象, 事件触发的节点部位 'before' | 'body' | 'after'
node-dragover dragover 时触发 节点信息 , 拖拽事件对象, 事件触发的节点部位 'before' | 'body' | 'after'
node-dragleave dragleave 时触发 节点信息 , 拖拽事件对象, 事件触发的节点部位 'before' | 'body' | 'after'
node-drop 放置节点时触发 节点信息 , 拖拽事件对象, 事件触发的节点部位 'before' | 'body' | 'after'

VTree Methods

方法 说明 参数 返回值
setData 使用此方法重置树数据,可避免大量数据被 vue 监听 data: object[]: 同 data Prop void
setChecked 设置多选选中/取消选中 key: string | number: 节点 key
value: boolean: 是否选中
void
setCheckedKeys 批量设置选中/取消选中 keys: Array<string | number>: 节点 key
value: boolean: 是否选中
void
checkAll 设置所有数据全选 void
clearChecked 清空选中 void
setSelected 设置单选选中/取消选中 key: string | number: 节点 key
value: boolean: 是否选中
void
setExpand 设置展开/折叠 key: string | number: 节点 key
value: boolean: 是否展开
expandParent: boolean = true: 如果是展开是否同时展开父节点 2.0.6
void
setExpandKeys 批量展开/折叠 keys: Array<string | number>: 节点 key
value: boolean: 是否展开
void
setExpandAll 设置全部展开/折叠 value: boolean: 是否展开 void
getCheckedNodes 获取多选选中节点 ignoreMode: 'none' | 'parents' | 'children': 需要忽略的部分,默认为 ignoreMode Prop TreeNode[]
getCheckedKeys 获取多选选中节点 key ignoreMode: 'none' | 'parents' | 'children': 需要忽略的部分,默认为 ignoreMode Prop Array<string | number>
getIndeterminateNodes 获取半选状态的节点 TreeNode[]
getSelectedNode 获取单选选中节点 TreeNode | null
getSelectedKey 获取单选选中节点 key TreeNode | null
getExpandNodes 获取展开的节点 TreeNode[]
getExpandKeys 获取展开的节点 key TreeNode[]
getCurrentVisibleNodes 获取当前可见的节点 TreeNode[]
getNode 根据 key 获取节点 key: string | number: 节点 key TreeNode | null
getTreeData 获取树形结构的节点数据 TreeNode[]
getFlatData 获取扁平化后的节点数据 TreeNode[]
getNodesCount 获取节点总数量 number
insertBefore 在参照节点前插入一个节点 insertedNode: 节点 key 或者单个节点数据
referenceKey: string | number: 参照节点 key
TreeNode | null 返回插入的节点
insertAfter 在参照节点后插入一个节点 insertedNode: 节点 key 或者单个节点数据
referenceKey: string | number: 参照节点 key
TreeNode | null 返回插入的节点
append 在父节点第一层子节点的末尾插入一个节点 insertedNode: 节点 key 或者单个节点数据
parentKey: string | number: 父节点 key
TreeNode | null 返回插入的节点
prepend 在父节点第一层子节点的开头插入一个节点 insertedNode: 节点 key 或者单个节点数据
parentKey: string | number: 父节点 key
TreeNode | null 返回插入的节点
remove 删除节点 removedKey: string | number: 要删除的节点 key TreeNode | null 返回删除的节点
filter 过滤节点 keyword: string: 过滤关键词
filterMethod: (keyword: string, node: TreeNode) => boolean: 过滤方法,默认为 filterMethod Prop ,如果没有传 filterMethod Prop 则为搜索 title 字段的一个内置方法
void
showCheckedNodes 展示已选节点 showUnloadCheckedNodes: boolean: 是否显示未加载的选中节点,默认为 Prop 传入的值 void
loadRootNodes 从远程加载根节点 Promise<void>
scrollTo 滚动到指定节点位置 key: string | number: 节点 key
verticalPosition: 'top' | 'center' | 'bottom' | number: 滚动的垂直位置
void

VTree Slots

名称 说明
empty 暂无数据
loading 加载中显示的图标

VTree Data Fields

注:以 '_' 开头的字段最好不要覆盖,以免影响内部处理逻辑

字段 说明
id 默认以 'id' 作为 key 字段,也可以通过 keyField Prop 指定其他字段作为 key 字段
title 默认显示的名称,可通过 titleField Prop 指定其他字段作为 title 字段
checked 多选模式下是否勾选
selected 单选模式下是否选中
indeterminate 多选模式下是否半选状态
disabled 是否禁用
expand 父节点有效,节点展开状态
visible 是否可见
_filterVisible 过滤后是否可见,如果为 false 则在其他可见情况下也是不可见的
_parent 父节点
children 子节点数组
isLeaf 标记节点是否为叶子节点
_level 节点层级,默认从 0 开始
_loading 节点是否正在加载
_loaded 节点是否已经加载过,异步加载下有效

VTreeSearch API

VTreeSearch Props

注:可在 VTreeSearch 上直接使用 VTree 的所有 Props

属性 说明 类型 默认值
searchPlaceholder 搜索输入框的 placeholder string '搜索关键字'
showCheckAll 是否显示全选复选框 boolean true
showCheckedButton 是否显示已选按钮 boolean true
checkedButtonText 已选按钮文字 string '已选'
showFooter 是否显示底部信息 boolean true
searchMethod 2.0.2 如果传入此 Prop ,触发 search 事件后将会执行此方法,否则会执行组件内置的搜索方法 (keyword: string) => void | Promise<void>
searchLength 触发搜索的字符长度 number 1
searchDisabled 禁用搜索功能 boolean false
searchRemote 是否远程搜索,传入 searchMethod 时无效 boolean false
searchDebounceTime 搜索防抖时间,单位为毫秒 number 300

VTreeSearch Events

注:可在 VTreeSearch 上直接监听 VTree 的所有 Events

事件名 说明 返回值
search 执行搜索操作时触发 搜索的关键字

VTreeSearch Methods

注:可在 VTreeSearch 上直接调用 VTree 的所有 Methods

方法 说明 参数 返回值
clearKeyword 清空关键字 void
getKeyword 获取搜索关键字 string
search 执行搜索 keyword: string: 搜索的关键字,默认为内部 this.keyword Promise<void>

VTreeSearch Slots

注:可在 VTreeSearch 上直接传入 VTree 的所有 Slots

名称 说明
search-input 搜索输入框,可通过此 slot 自行封装树搜索组件的行为
actions 操作按钮,可在搜索输入框后加入更多操作按钮
footer 底部信息

VTreeDrop API

VTreeDrop Props

注:可在 VTreeDrop 上直接使用 VTreeVTreeSearch 的所有 Props

属性 说明 类型 默认值
dropHeight 下拉内容高度 number 300
dropPlaceholder 展示输入框 placeholder string
dropDisabled 是否禁用 boolean false
clearable 允许清空 boolean false
placement 下拉弹出框位置,注意!!不支持自动识别方向 'bottom-start' | 'bottom-end' | 'bottom' | 'top-start' | 'top-end' | 'top' 'bottom-start'
transfer 将下拉 DOM 转移到 body 中 boolean false
dropdownClassName 在下拉框容器上额外添加的 class string | string[]
dropdownMinWidth 2.0.1 下拉框容器最小宽度,未指定则默认为展示输入框宽度。 适合 transfer 为 false 时使用 number
dropdownWidthFixed 2.0.5 固定下拉框容器宽度,当内容超出最小宽度不会伸长,而是出现横向滚动条 boolean false

VTreeDrop Events

注:可在 VTreeDrop 上直接监听 VTreeVTreeSearch 的所有 Events

事件名 说明 返回值
dropdown-visible-change 下拉框出现或消失时触发 下拉框是否可见
clear 点击清空按钮时触发

VTreeDrop Methods

注:可在 VTreeDrop 上直接调用 VTreeVTreeSearch 的所有 Methods

VTreeDrop Slots

注:可在 VTreeDrop 上直接传入 VTreeVTreeSearch 的所有 Slots

名称 说明
默认 展示输入框
display 展示输入框的展示文字,如果有默认 slot 则此 slot 无效
clear 替换清空图标,如果有默认 slot 则此 slot 无效

默认 slot 与 display slot 的 Slot Props 2.3.0

/** 展示 slot 的 props */
slotProps: {
  /** 多选选中的节点 */
  checkedNodes: [] as TreeNode[],

  /** 多选选中的节点 key */
  checkedKeys: [] as Array<string | number>,

  /** 单选选中的节点 */
  selectedNode: null as TreeNode | null,

  /** 单选选中的节点 key */
  selectedKey: null as string | number | null,
},

注意checkedNodesselectedNode 只包含已加载的节点,如果设置了选中的值(比如设置了 value Prop),但没有设置树的数据,则这两个字段内容将为空;而 checkedKeysselectedKey 则会包含未加载的选中节点 key 。

vue-tree's People

Contributors

angrytoro avatar chuchencheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vue-tree's Issues

v3.2.0版本,底层节点会显示展开图标

Bug 描述
v3.2.0版本,底层节点会显示展开图标
路径:/src/components/TreeNode.vue

// v3.2.0版本
const expandCls = computed(() => {
      return [
        `${prefixCls}__square`,
        `${prefixCls}__expand`,
        {
          [`${prefixCls}__expand_active`]: props.data?.expand
        }
      ]
    })
// v3.1.0版本
const expandCls = computed(() => {
      return [
        `${prefixCls}__square`
        {
          [`${prefixCls}__expand_active`]: props.data?.expand
        }
      ]
    })

TreeDrop单选时报错

image
image
原因是$refs.treeRef 就不是RefImpl对象了,不需要.value,直接.titleField就好了

check和uncheck事件触发时,会先触发check事件

例如我要触发uncheck事件触发时,组件会先触发check事件,然后再触发uncheck事件,select和unselect同理
示例代码:

<script setup> // 树节点选择 const treeSelect = (node) => { console.log('触发选中') } // 树节点取消选择 const treeUnselect = (node) => { console.log('触发取消选中') } // 树选中 const treeCheck =(node) => { console.log('true') } // 树取消选中 const treeUncheck = (node) => { console.log('false') } </script>

typescript d.ts not work

Bug 描述
typescript 总是 any,无法使用api定义
image

组件版本

  • Vue: 2.7.16
  • @wsfe/vue-tree: 3.2.0

怎么修改某个节点的数据

问题描述
使用 setData 设置数据 (非响应式的方式,没有使用 :data 进行双向绑定),怎么修改某个节点的数据例如 title,然后树上此节点马上更新看到效果呢?

需求来源,例如重命名树的节点。

组件版本

  • Vue3
  • @wsfe/vue-tree ^3.2.0

某个节点下的数据太多时显示为空白

Bug 描述
某个节点下的数据太多时显示为空白,如图

SCR-20240327-qhwi

复现步骤
请描述复现步骤,并且提供最小可复现示例(CodeSandbox, CodePen 链接等)

期望表现

实际表现
数据量太大时树的节点显示为空。

组件版本

  • Vue: Vue 3.4
  • @wsfe/vue-tree: ^3.2.0
  • 其他可帮助复现的 npm 包名称及版本

额外信息
其他要补充的信息

如何自定义节点的渲染内容

image
只看到一个render属性,要求是一个function,但是vue不像react那样可以在函数中返回node节点。请问有具体的解决方案吗?

renderNodeAmount 不生效

例如 <Vtree ref="tree" :load="loadNodes" :render="nodeRender" :renderNodeAmount="100"/>:

  1. 节点使用动态加载,展开某个节点后 load 的函数中用 resolve([children]) 创建子节点。
  2. 某个节点下有 10000 个节点,发现展开这个节点的时候,10000 个子节点都会生成 DOM,而不是生成 renderNodeAmount + bufferNodeAmount 节点,然后在滚动的时候动态生成 DOM 节点。
  3. 发现这种情况下 <div class="ctree-tree__block-area"><div style="height: 0px"> 中 height 的值一直是 0px,而在线例子 https://wsfe.github.io/vue-tree/ 的 performance 里的这个节点的 height 会变化。

造成虚拟滚动不生效的会不会是动态加载的节点都不能使用虚拟滚动了?

优化建议

处理大数据的时候使用vue-worker多线程进行处理,避免页面卡死

建议增加节点渲染的slot

树节点可能会渲染比较复杂的DOM结构,通过slot放在template中会比 render 方法更加直观
参考element-plus的使用方式:

<VTree>
  <template #node={ node }>
    <div class="custom-node">{{ node.name }}</div>
  </template>
</VTree>

vue2下v-model不生效

Bug 描述

vue 2.6.14下,v-model不生效

复现步骤

https://stackblitz.com/edit/vitejs-vite-z2qafx?file=src%2Fmain.js,src%2FTreeDemo.vue,package.json,index.html

可以将stackblitz下载到本地,不清楚为什么stackblitz上会报错,会检测成vue3

期望表现
v-model可以正常使用

实际表现
v-model不生效

组件版本

  • Vue: 2.6.14
  • @wsfe/vue-tree: 3.1.0

额外信息

直接使用modelValue是可以的,猜测是兼容性的问题?

<VTree
      :modelValue="value"
      selectable
      draggable
      :data="data"
      clearable
      drop-placeholder="请选择"
      :dropdown-min-width="30"
      dropdown-width-fixed
    >
      <template #empty>slot 传进来的暂无数据</template>
    </VTree>

scrollTo 不生效

Bug 描述

const foundCatalog = data.treeData.find(c => c.title === props.catalog);
if (foundCatalog) {
    setTimeout(() => {
        tree.value.scrollTo({ key: foundCatalog.id, verticalPosition: 'top' });
        console.log('scroll to ' + foundCatalog.id);
    }, 1000); // 担心树节点显示不完全,所以故意 1S 后才滚动。
}

复现步骤
请描述复现步骤,并且提供最小可复现示例(CodeSandbox, CodePen 链接等)

期望表现
把指定 ID 的节点滚动到顶部。

实际表现
没有滚动反应。

组件版本

  • Vue: 3.3
  • @wsfe/vue-tree: 3.1.0

ie11 堆栈溢出

IE11浏览器打开,堆栈溢出,不清楚是不是过多的函数调用引起的

右键菜单事件没有 event 参数

右键菜单事件 node-right-click 的参数只有 node,没有 event 参数,这样在弹出右键菜单的时候就不能把右键菜单在鼠标点下的位置弹出。

求助

./node_modules/@wsfe/vue-tree/dist/vue-tree.mjs 1302:13
Module parse failed: Unexpected token (1302:13)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
这个是啥原因啊

两点建议

Vue2版本的控件功能API十分强大,因为在vue2的各大UI库中的树形控件都没有虚拟滚动的功能,这个组件完美解决了vue2在中后台大数据量树形控件的问题,感谢作者的开源!

使用下来基本业务需求都能涵盖,不过提两点可以优化的UI建议,仅针对于vue2,因为现在vue3的UI库树形控件基本都支持了大数据量以及一些常见的业务需求:

问题描述
1.增加展开/折叠的动画过渡效果
2.增加节点之间带连接线的树

组件版本

  • Vue2 @wsfe/ctree

关于 @wsfe/vue-tree 对 Vue2 支持的讨论

官方在 2023 年 12 月 31 日 停止了 Vue2 的支持 ,不再有后续更新。

本树组件原本预想通过 vue-demi 库同时兼容 Vue2, Vue3 ,但自发布 @wsfe/vue-tree 3.x 以来,不时会收到一些 Vue2 兼容性相关的 issue , Vue2, Vue3 的割裂带来的问题远比预想的多。

开这个 issue 有两个目的:

  1. 调查用户使用的版本。请留下您目前正在使用的 Vue 版本与树组件版本,有以下三个选项:
  • Vue2 & @wsfe/ctree
  • Vue2 & @wsfe/vue-tree
  • Vue3 & @wsfe/vue-tree
  1. 讨论对 Vue2 的支持。是否要停止 @wsfe/vue-tree 对 Vue2 的支持,或者有其他同时支持 Vue2, Vue3 的方案。

怎么只更新某一个节点的样式?

使用 setData() 的方式设置树的数据 (使用非响应式):

  1. 节点 node 当前是非叶子节点,其 node.isLeaf 为 false,有小三角形箭头。
  2. 手动修改 node.isLeaf = true 把节点修改为叶子节点,节点的样式没有变,即小三角形箭头还在。
  3. 调用树的方法 tree.value.clearChecked() 强制更新整棵树,这时 node 的小三角形箭头消失。

有没有更好的方法,只更新某个节点的样式?

报错无法使用

  1. import '@wsfe/vue-tree/style.css' css文件引入路径有误
  2. 报错如图:
    Snipaste_2024-03-15_16-00-51

使用 TS 的时候提示找不到定义

问题描述
使用 TS 的时候提示找不到定义,目前是在 shims.t.ds 中增加 declare module '@wsfe/vue-tree' 给忽略了。

Could not find a declaration file for module '@wsfe/vue-tree'. '/Users/biao/Documents/workspace/newdt/dsc-research/dsc-vue/node_modules/@wsfe/vue-tree/dist/v3/vue-tree.mjs' implicitly has an 'any' type.
  There are types at '/Users/biao/Documents/workspace/newdt/dsc-research/dsc-vue/node_modules/@wsfe/vue-tree/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@wsfe/vue-tree' library may need to update its package.json or typings.

组件版本
Vue3
@wsfe/vue-tree

可能的解决办法: 来自 ChatGPT

The error message you are seeing indicates that the module @wsfe/vue-tree does not have a declaration file (.d.ts) that specifies its types. As a result, TypeScript is unable to infer the types for the module, and it falls back to using the 'any' type by default.

To resolve this issue, you have a few possible options:

  1. Install Type Declarations: Check if there are any available type declarations for the @wsfe/vue-tree package. You can search for them on DefinitelyTyped (https://definitelytyped.org/) or other community-driven TypeScript type declaration repositories. If you find the appropriate type declaration file, you can install it using npm or yarn:

    npm install @types/wsfe__vue-tree --save-dev
    

    or

    yarn add @types/wsfe__vue-tree --dev
    
  2. Check for Updates: Ensure that you are using the latest version of the @wsfe/vue-tree package. Sometimes, package updates include improvements to their TypeScript type declarations.

  3. Contact the Package Maintainer: If the package still lacks TypeScript type declarations despite being up to date, you can reach out to the maintainers of the @wsfe/vue-tree package and ask them to include TypeScript type declarations in their package.

  4. Use TypeScript's any Type: If you are unable to find type declarations for the package and the maintainers have not provided them, you can use TypeScript's any type for the objects and variables related to the @wsfe/vue-tree module. However, this approach means that you won't be able to leverage TypeScript's static type checking for that specific module.

It's worth noting that option 1 (installing type declarations) is the most appropriate solution as it enables you to use TypeScript's type checking effectively and ensures better type safety in your codebase. However, if the type declarations are not available, you might have to resort to option 4 and use the any type, though this could result in potential issues due to the lack of type safety.

在append 和 prepend 节点到tree上时,报错

Bug 描述
tree.value.prepend 和 tree.value.append报错,TypeError: Cannot read properties of undefined (reading 'id')

我在ui上新建了一个node,然后再向这个node append或者prepend更多子node的时候,就报错了

似乎和这儿有关

parentNode.children[childrenLength - 1][this.options.keyField]

https://github.com/wsfe/vue-tree/blob/26b2b5045d58432849fc0c22ccfcde402f440e28/src/store/tree-store.ts#L734C20-L734C28

这里的代码,当parentnode的children为空的时候,这里就会异常。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.