# @devsun/vue3-simple-tree

> vue3-simple-tree is very simple tree library.

Latest version **0.0.1** (published 2023-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @devsun/vue3-simple-tree
pnpm add @devsun/vue3-simple-tree
yarn add @devsun/vue3-simple-tree
bun add @devsun/vue3-simple-tree
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2023-02-28 |
| First published | 2023-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 57.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | devsun |

## Links

- npm: https://www.npmjs.com/package/@devsun/vue3-simple-tree
- npm.io page: https://npm.io/package/@devsun/vue3-simple-tree

## Dependencies (1)

- [vue](https://npm.io/package/vue.md) ^3.2.45

## Recent versions

- 0.0.1 (latest) — 2023-02-28

## README

# Vue3 Simple Tree

vue3-simple-tree is very simple tree library.

It was based on Vue3, typescript.



## Setup

```sh
npm i @devsun/vue3-simple-tree
```



## Usage

### Component

You can use `<simple-tree />`:

```vue
<simple-tree
        ref="simpleTreeRef"
        :data="data"
        id-key="menuId"
        name-key="menuNm"
        parent-id-key="parentMenuId"
        root-id=""
        :checkable="checkable"
        :selectable="selectable"
        :draggable="draggable"
        :include-indeterminate="includeIndeterminate"
        :expand-all="expandAll"
        :expand-options="expandOptions"
        @check="handleCheckTree"
        @select="handleSelectTree"
></simple-tree>
```



### Attributes

| Name                  | Type                            | Default   | Description                                            |
| --------------------- | ------------------------------- | --------- | ------------------------------------------------------ |
| ref                   | String                          |           | used for tree API call                                 |
| data                  | Object[]                        | []        | **Required**                                           |
| idKey                 | String                          |           | **Required**<br />Using by id from data                |
| nameKey               | String                          |           | **Required**<br />Using by name from data              |
| parentIdKey           | String                          |           | **Required**<br />Using by parent id from data         |
| rootId                | String                          | undefined | parentId of root node from data                        |
| checkable             | Boolean                         | false     | Whether to show a checkbox                             |
| includeIndetereminate | Boolean                         | false     | Whether to include indeterminated node in checked data |
| selectable            | Boolean                         | false     | Whether to use the selection                           |
| draggable             | Boolean                         | false     | Whether to change the tree by drag and drop            |
| expandAll             | Boolean                         | true      | Whether to expand all nodes                            |
| expandOptions         | { ids: string[], level: number} |           | Expand specific nodes                                  |



## Event

#### check

`() => Object[]`

```vue
<simple-tree
        @check="handleCheckTree"
></simple-tree>
```

#### select

`() => Object`

```vue
<simple-tree
        @select="handleSelectTree"
></simple-tree>
```

### API

#### getCheckedData

`() => Object[]`

return checked data

```vue
<script lang="ts" setup>
	const simpleTreeRef = ref(null);
    function getCheckedData() {
       const checkedData =  simpleTreeRef.value.getCheckedData();
    }
</script>

<template>
	<simple-tree
        ref="simpleTreeRef"
        ...
	></simple-tree>
</template>
```

#### getChangedData

`() => Object[]`

return chagned data by drag and drop 

```vue
<script lang="ts" setup>
	const simpleTreeRef = ref(null);
    function getChangedData() {
       const changedData =  simpleTreeRef.value.getChangedData();
    }
</script>

<template>
	<simple-tree
        ref="simpleTreeRef"
        ...
	></simple-tree>
</template>
```

#### getSelectedData

`() => Object[]`

return selected data

```vue
<script lang="ts" setup>
	const simpleTreeRef = ref(null);
    function getSelectedData() {
       const selectedData =  simpleTreeRef.value.getSelectedData();
    }
</script>

<template>
	<simple-tree
        ref="simpleTreeRef"
        ...
	></simple-tree>
</template>
```

#### getData

`() => Object[]`

return latest data

```vue
<script lang="ts" setup>
	const simpleTreeRef = ref(null);
    function getData() {
       const latestData =  simpleTreeRef.value.getData();
    }
</script>

<template>
	<simple-tree
        ref="simpleTreeRef"
        ...
	></simple-tree>
</template>
```



##  Global Component

use gloabl component:

```typescript
// main.ts
import { plugin as SimpleTreePlugin } from '@devsunp/vue3-simple-tree';

const app = createApp(App);

// use plugin
app.use(SimpleTreePlugin);

app.mount('#app');
```

---
_Source: https://npm.io/package/@devsun/vue3-simple-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
