Getting Started with Vue Tree Component
Smart UI Vue examples target Vue 3 and Vite; enable TypeScript in create-vue when you want typed SFCs.
Demo source (Smart UI repo): vue/vue-3/src/tree/overview/App.vue
Scaffold with Vite (Vue 3)
Run the official scaffolding tool:
npm create vue@latest
You will be prompted for TypeScript, Router, Pinia, and other options. When unsure, accept defaults and enable features later.
cd <your-project-name> npm install npm install smart-webcomponents npm run dev
Vue + TypeScript
If you enabled TypeScript, use vite.config.ts with the same isCustomElement configuration as below so the compiler treats Smart UI tags as native custom elements.
Teach Vue about custom elements
Without this, Vue warns about unknown custom elements. Open vite.config.js or vite.config.ts and configure the Vue plugin so smart-* and legacy jqx-* tags are passed through to the DOM:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: tag => tag.startsWith('smart-') || tag.startsWith('jqx-')
}
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
App.vue example
Example from Smart UI Vue 3 demos for this widget:
<template>
<div class="vue-root">
<smart-tree id="tree">
<smart-tree-items-group>
<i class="material-icons"></i> Attractions
<smart-tree-item>Movies</smart-tree-item>
<smart-tree-item>Circus</smart-tree-item>
<smart-tree-item>Concerts</smart-tree-item>
<smart-tree-item>Monuments</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Dining
<smart-tree-item>Restaurants</smart-tree-item>
<smart-tree-item>Cafés</smart-tree-item>
<smart-tree-item>Bars</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Education
<smart-tree-item>Schools</smart-tree-item>
<smart-tree-item>Colleges</smart-tree-item>
<smart-tree-item>Universities</smart-tree-item>
<smart-tree-item>Educational courses</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Family
<smart-tree-item>Babysitting</smart-tree-item>
<smart-tree-item>Family trips</smart-tree-item>
<smart-tree-item>Theme parks</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Health
<smart-tree-item>Hospitals</smart-tree-item>
<smart-tree-item>Family physicians</smart-tree-item>
<smart-tree-item>Optics</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Office
<smart-tree-item>Offices for rent</smart-tree-item>
<smart-tree-item>Office equipment</smart-tree-item>
<smart-tree-item>Repair works</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Promotions
<smart-tree-item>Sales</smart-tree-item>
<smart-tree-item>Malls</smart-tree-item>
<smart-tree-item>Collective buying</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Radio
<smart-tree-item>Available stations</smart-tree-item>
<smart-tree-item>Search</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Recipes
<smart-tree-item>With meat</smart-tree-item>
<smart-tree-item>With fish</smart-tree-item>
<smart-tree-item>Vegetarian recipes</smart-tree-item>
<smart-tree-item>Vegan recipes</smart-tree-item>
<smart-tree-item>Desserts</smart-tree-item>
<smart-tree-item>Chef's recommendations</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Sports
<smart-tree-item>Football</smart-tree-item>
<smart-tree-item>Basketball</smart-tree-item>
<smart-tree-item>Tennis</smart-tree-item>
<smart-tree-item>Baseball</smart-tree-item>
<smart-tree-item>Cycling</smart-tree-item>
</smart-tree-items-group>
<smart-tree-items-group>
<i class="material-icons"></i> Travel
<smart-tree-item>Local destinations</smart-tree-item>
<smart-tree-item>Book tickets</smart-tree-item>
<smart-tree-item>Organised travel</smart-tree-item>
</smart-tree-items-group>
</smart-tree>
</div>
</template>
<script>
import { onMounted } from "vue";
import "smart-webcomponents/source/styles/smart.default.css";
import "smart-webcomponents/source/modules/smart.tree.js";
export default {
name: "app",
setup() {
onMounted(() => {});
}
};
</script>
<style>
/* fallback */
@font-face {
font-family: "Material Icons";
font-style: normal;
font-weight: 400;
src: url(https://fonts.gstatic.com/s/materialicons/v31/2fcrYFNaTjcS6g4U3t-Y5ZjZjT5FdEJ140U2DJYC3mY.woff2)
format("woff2");
}
.material-icons {
font-family: "Material Icons";
font-weight: normal;
font-style: normal;
font-size: inherit;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-webkit-font-feature-settings: "liga";
-webkit-font-smoothing: antialiased;
}
smart-tree {
width: 60%;
height: auto;
}
smart-tree i {
margin-right: 8px;
}
@media only screen and (max-width: 700px) {
smart-tree {
width: 100%;
height: 100%;
}
body,
html {
width: 100%;
height: 100%;
}
}
</style>
You can now use smart-tree in templates; bindings and events follow Vue's normal syntax.
Run and build
Development server:
npm run dev
Then open http://localhost:5173/.
Production build:
npm run build
Output goes to ./dist.
Read more about using Smart UI for Vue.
Common Use Cases
-
Load hierarchical data
Populate tree with nested items
tree.dataSource = [{ label: 'Parent', items: [ { label: 'Child 1' }, { label: 'Child 2' } ] }]; -
Expand/collapse nodes
Programmatically control node state
tree.expandItem('0'); // Expand first item tree.collapseItem('0'); // Collapse it -
Handle selection
Respond to tree item selection
tree.addEventListener('change', (e) => { console.log('Selected:', e.detail.value); });
Troubleshooting
- How do I load tree data lazily?
- Set items to a function that returns a Promise, or use the expanding event to load child nodes on demand.
- How do I enable drag and drop?
- Set allowDrag = true and allowDrop = true to enable drag-and-drop reordering.
Accessibility
The Tree component follows WAI-ARIA best practices:
- Keyboard navigation - Tab, Arrow keys, Enter, and Escape are supported
- ARIA roles - Appropriate roles and labels are applied automatically
- Focus management - Visible focus indicators for keyboard users
- Screen readers - State changes are announced to assistive technology
- High contrast - Supports Windows High Contrast Mode and forced colors
For custom labeling, set aria-label or aria-labelledby attributes on the component.
Supported stacks: Smart UI targets Angular 17+, React 18+, Vue 3+, Node 18 LTS, and evergreen browsers; pin exact package versions to your org policy.