Skip to content

Folder 文件夹

用于展示目录树与文件预览,对齐 @ant-design/x Folder

何时使用

  • 需要在对话或工作区中浏览目录结构并预览文件内容时。

代码演示

基本

基础目录树与文件预览。

src
App.vue
utils
index.ts
README.md
<script setup lang="ts">
import { ref } from 'vue';
const count = ref(0);
</script>

<template>
  <button @click="count++">{{ count }}</button>
</template>

API

FolderProps

属性说明类型默认值
treeData目录数据FolderTreeData[]-
selectable是否可选中文件booleantrue
selectedFile受控选中路径(路径片段数组)string[]-
defaultSelectedFile默认选中路径string[]-
expandedPaths受控展开路径(完整 path key)string[]-
defaultExpandedPaths默认展开路径string[]-
defaultExpandAll是否默认展开全部booleantrue
directoryTreeWith左侧目录宽度(保留 React 拼写)number | string278
directoryIcons自定义图标,false 关闭图标false | Record<string, VNode>-
directoryTitle目录区标题,false 隐藏false | VNode | string | () => VNode-
previewTitle预览区标题,false 隐藏false | VNode | function-
previewRender自定义预览内容VNode | function-
emptyRender空状态,false 隐藏false | VNode | () => VNode-
fileContentService异步加载文件内容{ loadFileContent(path): Promise<string> }-
contextMenu右键菜单ItemType[] | function-
onSelectedFileChange选中文件变化(file) => void-
onExpandedPathsChange展开路径变化(paths) => void-
onFileClick点击文件(path, content?) => void-
onFolderClick点击文件夹(path) => void-

FolderTreeData

属性说明类型
title展示标题VNode | string
path路径片段(非完整路径)string
content文件内容string
children子节点;存在且长度 > 0 视为文件夹,空数组视为文件FolderTreeData[]
contextMenu节点级右键菜单,false 禁用ItemType[] | false | function

FolderRef

方法说明
nativeElement根 DOM
getNode(path)按路径获取节点
updateNode(path, data)不可变更新,返回新 treeData
deleteNode(path)不可变删除
addNode(parentPath, node)不可变新增子节点

贡献者

贡献者

正在加载贡献者信息...