Notice that nodes must have a unique key defined by a property of each key. In the example above, labels are unique so we’re using label prop to define these keys. However, you can add any property to the nodes (like ‘id’ or anything you want) and then use that property (like node-key="id").
Vue Properties
Vue Property
Type
Description
nodes
Array
Vue model for the Tree
node-key
String
Property of node to use as unique key.
label-key
String
(v0.17.11+) Property of node to use as label.
color
String
Color of the connector lines.
control-color
String
Color of checkboxes.
text-color
String
Color of text.
dark
Boolean
When rendering on a dark background.
icon
String
Connector icon for each node.
selected
Any
Use .sync. The unique key value of the selected node.
tick-strategy
String
One of ‘leaf’, ‘leaf-filtered’, ‘strict’, ‘none’.
ticked
Array
Use .sync. Node unique keys of ticked nodes.
expanded
Array
Use .sync. Node unique keys of expanded nodes.
default-expand-all
Boolean
Expan all nodes on first render.
accordion
Boolean
Expanding a node closes its siblings.
filter
String
String to be used when filtering nodes.
filter-method
Function
Custom filtering method.
no-nodes-label
String
Override default i18n of message when no nodes are available.
no-results-label
String
Override default i18n of message when no nodes are available after filtering.
duration
Number
(v0.17.13+) Toggle animation duration in milliseconds. Default: 300
Nodes model structure
The following describes a node’s properties that are taken into account by QTree’s v-model.
Node Property
Type
Description
label
String
Node’s label
icon
String
Node’s icon
iconColor
String
(v0.17.9+) Node’s icon color. One from Quasar Color Palette.
img
String
Node’s image. Use statics folder. Example: ‘statics/mountains.png’
avatar
String
Node’s avatar. Use statics folder. Example: ‘statics/boy-avatar.png’
children
Array
Array of nodes as children.
disabled
Boolean
Is node disabled?
expandable
Boolean
Is node expandable?
tickable
Boolean
When using a tick strategy, each node shows a checkbox. Should a node’s checkbox be disabled?
noTick
Boolean
When using a tick strategy, should node display a checkbox?
tickStrategy
String
Override global tick strategy for this node only. One of ‘leaf’, ‘leaf-filtered’, ‘strict’, ‘none’.
lazy
Boolean
Should children be lazy loaded? In this case also don’t specify ‘children’ prop.
header
String
Node header scoped slot name, without the required ‘header-‘ prefix. Example: ‘story’ refers to ‘header-story’ scoped slot.
body
String
Node body scoped slot name, without the required ‘body-‘ prefix. Example: ‘story’ refers to ‘body-story’ scoped slot.
Selection vs Ticking, Expansion
Selection (through QTree selected prop) refers to the currently selected node (gets highlighted with different background).
Ticking (through QTree ticked prop) refers to the checkbox associated with each node.
Expansion (through QTree expanded prop) refers to the nodes that are expanded.
All properties above require the .sync modifier in order for them to work correctly. Example:
<!-- DO NOT forget about adding ".sync" --> <q-treeselected.sync="selection"...
Tick Strategy
There are three ticking strategy: ‘leaf’, ‘leaf-filtered’, ‘strict’ with an additional (and default) ‘none’ which disables ticking.
Strategy
Description
leaf
Ticked nodes are only the leaves. Ticking a node influences the parent’s ticked state too (parent becomes partially ticked or ticked), as well as its children (all tickable children become ticked).
leaf-filtered
Same concept as leaf, only that this strategy applies only to filtered nodes (the nodes that remain visible after filtering).
strict
Ticked nodes are independent of parent or children tick state.
You can apply a global tick strategy for a QTree and locally change the ticking strategy for a certain node by specifying the tickStrategy in the nodes model.
Custom Filter Method
You can customize the filtering method by specifying the filter-method prop. The method below is actually the default filtering strategy:
<divslot="body-story"slot-scope="prop"> <spanclass="text-weight-thin">The story is:</span> {{ prop.node.story }} </div>
<divslot="body-toggle"slot-scope="prop"> <pclass="caption">{{ prop.node.caption }}</p> <q-togglev-model="prop.node.enabled"label="I agree to the terms and conditions" /> </div> </q-tree> </template>
<script> exportdefault { data: () => ({ customize: [ { label: 'Satisfied customers', header: 'root', children: [ { label: 'Good food', icon: 'restaurant_menu', header: 'generic', children: [ { label: 'Quality ingredients', header: 'generic', body: 'story', story: 'Lorem ipsum dolor sit amet.' }, { label: 'Good recipe', body: 'story', story: 'A Congressman works with his equally conniving wife to exact revenge on the people who betrayed him.' } ] }, { label: 'Good service', header: 'generic', body: 'toggle', caption: 'Why are we as consumers so captivated by stories of great customer service? Perhaps it is because...', enabled: false, children: [ { label: 'Prompt attention' }, { label: 'Professional waiter' } ] }, { label: 'Pleasant surroundings', children: [ { label: 'Happy atmosphere' }, { label: 'Good table presentation', header: 'generic' }, { label: 'Pleasing decor' } ] } ] } ] }) } </script>
<divslot="default-body"slot-scope="prop"> <divv-if="prop.node.story"> <spanclass="text-weight-thin">This node has a story</span>: {{ prop.node.story }} </div> <spanv-elseclass="text-weight-thin">This is some default content.</span> </div> </q-tree> </template>
<script> exportdefault { data: () => ({ customize: [ { label: 'Satisfied customers', header: 'root', children: [ { label: 'Good food', icon: 'restaurant_menu', header: 'generic', children: [ { label: 'Quality ingredients', header: 'generic', body: 'story', story: 'Lorem ipsum dolor sit amet.' }, { label: 'Good recipe', body: 'story', story: 'A Congressman works with his equally conniving wife to exact revenge on the people who betrayed him.' } ] }, { label: 'Good service', header: 'generic', body: 'toggle', caption: 'Why are we as consumers so captivated by stories of great customer service? Perhaps it is because...', enabled: false, children: [ { label: 'Prompt attention' }, { label: 'Professional waiter' } ] }, { label: 'Pleasant surroundings', children: [ { label: 'Happy atmosphere' }, { label: 'Good table presentation', header: 'generic' }, { label: 'Pleasing decor' } ] } ] } ] }) } </script>