Im using vuetify's treeview component and I want the last child in each node to be a router link, does anyone know how to achieve this?
Even if I could just bind an @click event that would work for me.
I cannot see in the docs or examples how to do this.
This is what my component looks like:
<template>
<div>
<v-treeview :items="items"></v-treeview>
</div>
</template>
<script>
export default {
data: () => ({
items: [
{
name: 'Parent',
children: [
{
name: 'Child1',
to:'booking' // <---I want to put a router link here or click event handler
}
]
}
]
})
}
</script>
You need to use a scoped slot for your labels:
<template>
<div>
<v-treeview :items="items">
<template slot="label" slot-scope="props">
<router-link :to="props.item.to">{{ props.item.name }}</router-link>
</template>
</v-treeview>
</div>
</template>
You should also make sure to display data that do not have the to property without a link. You can use a simple v-if for that:
<template>
<div>
<v-treeview :items="items">
<template slot="label" slot-scope="props">
<router-link :to="props.item.to" v-if="props.item.to">{{ props.item.name }}</router-link>
<span v-else>{{ props.item.name }}</span>
</template>
</v-treeview>
</div>
</template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With