我最近开始使用 Vue 3 和 Headless UI。
我创建了一个ListBox
组件,用于App.vue
显示列表People
并按预期工作。
我希望把它变成一个可重用的组件,用于显示People
和Countries
.
如何将我的组件更改为对这两种类型都是动态的?
列表框.vue
<template>
<Listbox v-model="selectedPerson">
<ListboxButton class=" bg-white shadow-sm border-gray-500 border-2 shadow-gray-200 font-bold p-4 text-left rounded-md">
{{ selectedPerson.name }}
</ListboxButton>
<ListboxOptions class="mt-2">
<ListboxOption
as="template" v-slot="{ active }"
v-for="person in people" :key="person"
:value="person">
<li :class="{
'bg-blue-500 text-white p-6': active,
'bg-white shadow-lg p-6 text-black ': !active
}">
{{ person.name }}
</li>
</ListboxOption>
</ListboxOptions>
</Listbox>
</template>
<script setup>
import { ref } from 'vue'
import {
Listbox,
ListboxLabel,
ListboxButton,
ListboxOptions,
ListboxOption,
} from '@headlessui/vue'
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
]
const selectedPerson = ref(people[0])
</script>
应用程序.vue:
<template>
<ListBox />
</template>