P粉7868001742023-08-27 00:44:36
The props
object passed to the slot contains an onClick
callback, which you need to bind for selection to work:
<template #item="{ item, props: { onClick } }" > <v-list-item :title="item.title" @click="onClick"/> </template>
Documentation is a bit sparse at the moment, the type given is Record
. In Vuetify 3.4, other values are key
, title
, value
and ref
(template reference from underlying VVritualScroll) Used to update the height of the scroll bar.
When using a component with a title
property (e.g. VListItem), you can bind the entire props
object:
<template #item="{ props }" > <v-list-item v-bind="props"/> </template>
(BTW, the #item
slot has its content rendered into the v-list
, no need to wrap it again)
This is a snippet:
const { createApp, ref } = Vue; const { createVuetify } = Vuetify const vuetify = createVuetify() createApp({ setup(){ return { tag: ref(null), tags: [ { title: 'example1', value: 0 }, { title: 'example2', value: 1 }, ], } } }).use(vuetify).mount('#app')
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.css" /> <link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet"> <div id="app" class="d-flex justify-center"> <v-app> <div> <v-select style="width: 300px;" v-model="tag" :items="tags" variant="solo" label="Tags" > <template #item="{ item, props: {onClick, title, value} }" > <v-list-item :title="item.title" @click="onClick"/> </template> </v-select> Selected: {{tag}} </div> </v-app> </div> <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script> <script src="https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.js"></script>