## Tree
Display a set of data with hierarchies.
### Basic usage
Basic tree structure.
:::demo
```html
```
:::
### Selectable
Used for node selection.
:::demo This example also shows how to load node data asynchronously.
```html
```
:::
### Custom leaf node in lazy mode
:::demo A node's data is not fetched until it is clicked, so the Tree cannot predict whether a node is a leaf node. That's why a drop-down button is added to each node, and if it is a leaf node, the drop-down button will disappear when clicked. That being said, you can also tell the Tree in advance whether the node is a leaf node, avoiding the render of the drop-down button before a leaf node.
```html
```
:::
### Disabled checkbox
The checkbox of a node can be set as disabled.
:::demo In the example, 'disabled' property is declared in defaultProps, and some nodes are set as 'disabled:true'. The corresponding checkboxes are disabled and can't be clicked.
```html
```
:::
### Default expanded and default checked
Tree nodes can be initially expanded or checked
:::demo Use `default-expanded-keys` and `default-checked-keys` to set initially expanded and initially checked nodes respectively. Note that for them to work, `node-key` is required. Its value is the name of a key in the data object, and the value of that key should be unique across the whole tree.
```html
```
:::
### Checking tree nodes
:::demo This example shows how to get and set checked nodes. They both can be done in two approaches: node and key. If you are taking the key approach, `node-key` is required.
```html
  get by node
  get by key
  set by node
  set by key
  reset
```
:::
### Custom node content
The content of tree nodes can be customized, so you can add icons or buttons as you will
:::demo Use `render-content` to assign a render function that returns the content of tree nodes. See Vue's documentation for a detailed introduction of render functions. Note that this demo can't run in jsfiddle because it doesn't support JSX syntax. In a real project, `render-content` will work if relevant dependencies are correctly configured.
```html
```
:::
### Tree node filtering
Tree nodes can be filtered
:::demo Invoke the `filter` method of the Tree instance to filter tree nodes. Its parameter is the filtering keyword. Note that for it to work, `filter-node-method` is required, and its value is the filtering method.
```html
```
:::
### Accordion
Only one node among the same level can be expanded at one time.
:::demo
```html
```
:::
### Attributes
| Attribute             | Description                              | Type                        | Accepted Values | Default |
| --------------------- | ---------------------------------------- | --------------------------- | --------------- | ------- |
| data                  | tree data                                | array                       | —               | —       |
| empty-text            | text displayed when data is void         | string                      | —               | —       |
| node-key              | unique identity key name for nodes, its value should be unique across the whole tree | string                      | —               | —       |
| props                 | configuration options, see the following table | object                      | —               | —       |
| render-after-expand   | whether to render child nodes only after a parent node is expanded for the first time | boolean | — | true |
| load                  | method for loading subtree data, only works when `lazy` is true  | function(node, resolve)     | —               | —       |
| render-content        | render function for tree node            | Function(h, { node, data, store }        | —               | —       |
| highlight-current     | whether current node is highlighted      | boolean                     | —               | false   |
| default-expand-all    | whether to expand all nodes by default   | boolean                     | —               | false   |
| expand-on-click-node  | whether to expand or collapse node when clicking on the node, if false, then expand or collapse node only when clicking on the arrow icon. | —                           | true            |         |
| auto-expand-parent    | whether to expand father node when a child node is expanded | boolean                     | —               | true    |
| default-expanded-keys | array of keys of initially expanded nodes | array                       | —               | —       |
| show-checkbox         | whether node is selectable               | boolean                     | —               | false   |
| check-strictly        | whether checked state of a node not affects its father and child nodes when `show-checkbox` is `true` | boolean                     | —               | false   |
| default-checked-keys  | array of keys of initially checked nodes | array                       | —               | —       |
| filter-node-method    | this function will be executed on each node when use filter method. if return `false`, tree node will be hidden. | Function(value, data, node) | —               | —       |
| accordion             | whether only one node among the same level can be expanded at one time | boolean                     | —               | false   |
| indent                | horizontal indentation of nodes in adjacent levels in pixels | number                     | —    | 16 |
| lazy                  | whether to lazy load leaf node, used with `load` attribute  | boolean                     | —    | false |
### props
| Attribute | Description                              | Type   | Accepted Values | Default |
| --------- | ---------------------------------------- | ------ | --------------- | ------- |
| label     | specify which key of node object is used as the node's label | string, function(data, node) | —               | —       |
| children | specify which node object is used as the node's subtree | string, function(data, node) | —               | —       |
| disabled | specify which key of node object represents if node's checkbox is disabled | boolean, function(data, node) | —    | —    |
| isLeaf | specify whether the node is a leaf node | boolean, function(data, node) | —    | —    |
### Method
`Tree` has the following method, which returns the currently selected array of nodes.
| Method          | Description                              | Parameters                               |
| --------------- | ---------------------------------------- | ---------------------------------------- |
| filter          | filter all tree nodes, filtered nodes will be hidden | Accept a parameter which will be used as first parameter for filter-node-method |
| updateKeyChildren | set new data to node, only works when `node-key` is assigned  | (key, data) Accept two parameters: 1. key of node 2. new data |
| getCheckedNodes | If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes | Accept a boolean type parameter whose default value is `false`. If the parameter is `true`, it only returns the currently selected array of sub-nodes. |
| setCheckedNodes | set certain nodes to be checked, only works when `node-key` is assigned | an array of nodes to be checked          |
| getCheckedKeys  | If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of node's keys | (leafOnly) Accept a boolean type parameter whose default value is `false`. If the parameter is `true`, it only returns the currently selected array of sub-nodes. |
| setCheckedKeys  | set certain nodes to be checked, only works when `node-key` is assigned | (keys, leafOnly) Accept two parameters: 1. an array of node's keys to be checked 2. a boolean type parameter whose default value is `false`. If the parameter is `true`, it only returns the currently selected array of sub-nodes. |
| setChecked      | set node to be checked or not, only works when `node-key` is assigned | (key/data, checked, deep) Accept three parameters: 1. node's key or data to be checked 2. a boolean typed parameter indicating checked or not. 3. a boolean typed parameter indicating deep or not. |
| getCurrentKey   | return the highlight node's key (null if no node is highlighted) | — |
| getCurrentNode  | return the highlight node (null if no node is highlighted) | — |
| setCurrentKey   | set highlighted node by key, only works when `node-key` is assigned | (key) the node's key to be highlighted |
| setCurrentNode  | set highlighted node, only works when `node-key` is assigned | (node) the node to be highlighted |
### Events
| Event Name     | Description                              | Parameters                               |
| -------------- | ---------------------------------------- | ---------------------------------------- |
| node-click     | triggers when a node is clicked          | three parameters: node object corresponding to the node clicked, `node` property of TreeNode, TreeNode itself |
| check-change   | triggers when the selected state of the node changes | three parameters: node object corresponding to the node whose selected state is changed, whether the node is selected, whether node's subtree has selected nodes |
| current-change | triggers when current node changes       | two parameters: node object corresponding to the current node, `node` property of TreeNode |
| node-expand    | triggers when current node open          | three parameters: node object corresponding to the node opened, `node` property of TreeNode, TreeNode itself |
| node-collapse  | triggers when current node close         | three parameters: node object corresponding to the node closed, `node` property of TreeNode, TreeNode itself |