# Showing Loading State When Expanding Nodes in Kendo UI for Vue TreeView

## Environment

<table>
<tbody>
<tr>
<td>Product</td>
<td>Kendo UI for Vue TreeView</td>
</tr>
<tr>
<td>Version</td>
<td>Current</td>
</tr>
</tbody>
</table>

## Description

I need to show a loading spinner when a node in the [Kendo UI for Vue TreeView](https://www.telerik.com/kendo-vue-ui/components/treeview) is expanding and data is being loaded from the server.

This knowledge base article also answers the following questions:

* How to add a loading spinner in Vue TreeView when expanding nodes?
* How to show a loading indicator for server requests in TreeView?
* How to implement a custom loading state in Kendo UI for Vue TreeView?

## Solution

Track a loading state for each node and use a custom item slot to display a [Loader](https://www.telerik.com/kendo-vue-ui/components/indicators/loader) next to the node text while its children are loading. The slot customizes the node content; it does not replace the built-in expand/collapse icon.

Follow these steps:

1. Set `hasChildren` to `true` for nodes whose children are not loaded yet, and leave their `items` field unset. This lets you expand a node before its children are available.
2. Handle the [`expandchange`](https://www.telerik.com/kendo-vue-ui/components/treeview/api/treeviewexpandchangeevent) event to toggle the node's `expanded` state. Request children only when the node is expanded, has no loaded items, and is not already loading.
3. Set the node's `loading` flag before starting the request. Assign the returned children to `items`, update `hasChildren` to reflect the result, and clear the flag in a `finally` block.
4. Set the TreeView's [`item`](https://www.telerik.com/kendo-vue-ui/components/treeview/api/treeviewprops#item) prop to a named slot. In the slot, use `v-if` to render the Loader only while that node's loading flag is active.

### Runnable Example

The following example simulates a server request with a 1.5-second delay. Expand Furniture or Decor to see the loader, then expand Bed Linen to load another level. Loaded children are reused when you collapse and expand a node again.

Replace the `loadChildren` function with your server request when using this approach in your application.

[Demo Source](https://demos.telerik.com/kendo-vue-ui/knowledge-base/treeview-loading-spinner-expanding-node/source.txt)

## See Also

* [Kendo UI for Vue TreeView Documentation](https://www.telerik.com/kendo-vue-ui/components/treeview)
* [Kendo UI for Vue Loader Documentation](https://www.telerik.com/kendo-vue-ui/components/indicators/loader)
* [Loading TreeView Data on Demand](https://www.telerik.com/kendo-vue-ui/components/treeview/data-binding#loading-data-on-demand)
* [TreeView ExpandChange Event API Reference](https://www.telerik.com/kendo-vue-ui/components/treeview/api/treeviewexpandchangeevent)
