Rumah > Soal Jawab > teks badan
P粉7868001742023-08-27 00:44:36
Panggil balik props
对象包含一个 onClick
dihantar ke slot, anda perlu mengikatnya agar pemilihan berfungsi:
<template #item="{ item, props: { onClick } }" > <v-list-item :title="item.title" @click="onClick"/> </template>
Dokumentasi agak jarang buat masa ini, jenis yang diberikan ialah Record
。在 Vuetify 3.4 中,其他值是 key
、title
、value
和 ref
(rujukan templat dari asas) VVritualScroll digunakan untuk mengemas kini ketinggian bar skrol.
Apabila menggunakan komponen dengan atribut title
(contohnya VListItemtitle
属性的组件时(例如 VListItem),您可以绑定整个 props
), anda boleh mengikat keseluruhan objek props
:
<template #item="{ props }" > <v-list-item v-bind="props"/> </template>
(By the way, #item
插槽已将其内容渲染到 v-list
sederhana, tak perlu bungkus semula)
Ini klip:
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>