npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vue3-file-tree

v0.1.6

Published

文件树

Downloads

35

Readme

vue3-file-tree

文件树

vue3-file-tree的安装

pnpm 安装
pnpm add vue3-file-tree
npm 安装
npm install vue3-file-tree

vue3-file-tree的使用

配置

props:
    treeData: TreeList // 数据树
    defaultFile?: number // 默认选中文件
    expandAll?: boolean // 是否全展开
    customize?: boolean // 自定义folder和file
    space?: number // 每层之间的间距,默认20

emits:
    change(file) // file的类型结构为FileType

数据类型type

interface FolderType {
  id: number
  isOpen?: boolean // 是否打开目录
  name: string
  children: TreeList
  isFolder: boolean
  level?: number // 层级
  parentId?: number // 上层目录id,最上层默认为0
  [key: string]: any
}

interface FileType {
  id: number
  name: string
  isFolder?: boolean
  level?: number // 层级
  parentId?: number // 上层目录id,最上层默认为0
  [key: string]: any
}

type TreeList = (FolderType | FileType)[]

使用范例

样式文件 src/components/global.scss

样式文件需要手动导入,也可以使用自己的样式

// 导入默认样式
// 需要安装sass
// npm i -D sass
import 'vue3-file-tree/dist/global.scss'

操作树方法

使用ref获取Tree component,调用方法

// 更新树的参数,updateObject可以是FileType或FolderType里部分参数
update(id: number, updateObject: { [key: string]: any })
// id为文件的id,这个方法不会选中文件,只展开
expand(id: number)
// id为文件的id,这个方法会选中文件,并展开,还会调用change方法
setActiveFile(id: number)
范例文件:App.vue
<script setup lang="ts">
import { Tree } from './components'
import type { FileType, TreeList } from './components/type'
import './components/global.scss'
import { onMounted, ref } from 'vue'
const treeData: TreeList = [
  {
    id: 88,
    name: 'Fire fire',
    isFolder: true,
    children: [
      {
        id: 89,
        name: 'good'
      },
      {
        id: 78,
        name: 'Fire fire2',
        isFolder: true,
        children: [
          {
            id: 790,
            name: 'good2'
          }
        ]
      }
    ]
  },
  {
    id: 79,
    name: 'good2'
  },
  {
    id: 80,
    name: 'Fire fire4',
    isFolder: true,
    children: []
  }
]

const change = (file: FileType) => {
  console.log(file)
}
const tree = ref()

onMounted(() => {
  setTimeout(() => {
    tree.value.update(79, { name: 'test' })
  }, 1000)

  setTimeout(() => {
    tree.value.expand(790)
  }, 2000)

  setTimeout(() => {
    tree.value.setActiveFile(790)
  }, 3000)
})
</script>

<template>
  <div class="tree-template">
    <Tree
      ref="tree"
      :treeData="treeData"
      :defaultFile="79"
      :expandAll="false"
      @change="change"
      :customize="false"
    >
      <template #folder="{ folder }"> folder:{{ folder.name }} </template>
      <template #file="{ file }"> file:{{ file.name }} </template>
    </Tree>
  </div>
</template>
<style lang="scss">
.tree-template {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 400px;
  left: 0;
  background-color: #fff;
}
</style>

</style>