76 lines
2.2 KiB
Vue
76 lines
2.2 KiB
Vue
<script setup lang="ts">
|
||
import {
|
||
Select,
|
||
SelectTrigger,
|
||
SelectValue,
|
||
SelectIndicator,
|
||
SelectPopover,
|
||
ListBox,
|
||
ListBoxItem,
|
||
ListBoxItemIndicator,
|
||
Label,
|
||
} from "@heroui-vue/components";
|
||
import { ref, computed } from "vue";
|
||
import type { SelectModelValue } from "@heroui-vue/components";
|
||
const states = [
|
||
{ id: "california", name: "加利福尼亚" },
|
||
{ id: "texas", name: "德克萨斯" },
|
||
{ id: "florida", name: "佛罗里达" },
|
||
{ id: "new-york", name: "纽约" },
|
||
{ id: "illinois", name: "伊利诺伊" },
|
||
{ id: "pennsylvania", name: "宾夕法尼亚" },
|
||
];
|
||
const state = ref<SelectModelValue>("california");
|
||
const selected = computed(
|
||
() =>
|
||
states
|
||
.filter((s) =>
|
||
Array.isArray(state.value)
|
||
? state.value.includes(s.id)
|
||
: state.value === s.id,
|
||
)
|
||
.map((s) => s.name)
|
||
.join(", ") || "无",
|
||
);
|
||
</script>
|
||
<template>
|
||
<div class="space-y-2">
|
||
<Select class="w-[256px]" placeholder="请选择州" v-model="state">
|
||
<Label>州(受控)</Label>
|
||
<SelectTrigger>
|
||
<SelectValue />
|
||
<SelectIndicator />
|
||
</SelectTrigger>
|
||
<SelectPopover>
|
||
<ListBox>
|
||
<ListBoxItem id="california" text-value="加利福尼亚">
|
||
加利福尼亚
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
<ListBoxItem id="texas" text-value="德克萨斯">
|
||
德克萨斯
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
<ListBoxItem id="florida" text-value="佛罗里达">
|
||
佛罗里达
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
<ListBoxItem id="new-york" text-value="纽约">
|
||
纽约
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
<ListBoxItem id="illinois" text-value="伊利诺伊">
|
||
伊利诺伊
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
<ListBoxItem id="pennsylvania" text-value="宾夕法尼亚">
|
||
宾夕法尼亚
|
||
<ListBoxItemIndicator />
|
||
</ListBoxItem>
|
||
</ListBox>
|
||
</SelectPopover>
|
||
</Select>
|
||
<p class="text-sm text-muted">已选:{{ selected }}</p>
|
||
</div>
|
||
</template>
|