LocaleSelect 组件扩展了 SelectMenu 组件,因此您可以传入任何属性,例如 color、variant、size 等。
使用 locales 属性,其值为来自 @nuxt/ui/locale 的语言环境数组。
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const locale = ref('en')
</script>
<template>
<ULocaleSelect v-model="locale" :locales="Object.values(locales)" class="w-48" />
</template>
您可以只传递应用程序中需要的语言环境
<script setup lang="ts">
import { en, es, fr } from '@nuxt/ui/locale'
const locale = ref('en')
</script>
<template>
<ULocaleSelect v-model="locale" :locales="[en, es, fr]" />
</template>
您可以将其与 Nuxt i18n 一起使用
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale, setLocale } = useI18n()
</script>
<template>
<ULocaleSelect
:model-value="locale"
:locales="Object.values(locales)"
@update:model-value="setLocale($event)"
/>
</template>
您可以将其与 Vue i18n 一起使用
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import * as locales from '@nuxt/ui/locale'
const { locale, setLocale } = useI18n()
</script>
<template>
<ULocaleSelect
:model-value="locale"
:locales="Object.values(locales)"
@update:model-value="setLocale($event)"
/>
</template>
| 属性 | 默认值 | 类型 |
|---|---|---|
modelValue | string | |
语言环境 | Locale<any>[]
| |
name | string字段的名称。作为名称/值对的一部分随其所属表单提交。 | |
avatar | AvatarProps在左侧显示头像。
| |
尺寸 | 'md' | "md" | "xs" | "sm" | "lg" | "xl" |
loading | boolean当为 | |
图标 | any根据 | |
color | 'primary' | "error" | "primary" | "secondary" | "success" | "info" | "warning" | "neutral" |
autofocus | boolean | |
disabled | boolean当为 | |
open | boolean组合框的受控打开状态。可以通过 | |
defaultOpen | boolean组合框初次渲染时的打开状态。 | |
resetSearchTermOnBlur | `true` | boolean当组合框输入失去焦点时是否重置搜索词 |
resetSearchTermOnSelect | `true` | boolean当组合框值被选中时是否重置搜索词 |
highlightOnHover | boolean当 | |
defaultValue | stringSelectMenu 初始渲染时的值。当您不需要控制 SelectMenu 的状态时使用。 | |
multiple | false是否可以选择多个选项。 | |
required | boolean | |
id | string | |
placeholder | string选择框为空时的占位符文本。 | |
searchInput | false | boolean | InputProps<AcceptableValue>是否显示搜索输入框。可以是对象,用于向输入框传递附加属性。 |
variant | 'outline' | "outline" | "soft" | "subtle" | "ghost" | "none" |
trailingIcon | appConfig.ui.icons.chevronDown | any用于打开菜单的图标。 |
selectedIcon | appConfig.ui.icons.check | any选中项时显示的图标。 |
内容 | { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' } | ComboboxContentProps & Partial<EmitsToProps<DismissableLayerEmits>>菜单的内容。
|
arrow | false | boolean | ComboboxArrowProps在菜单旁边显示一个箭头。 |
portal | true | string | false | true | HTMLElement在 portal 中渲染菜单。 |
virtualize | false | boolean | { overscan?: number ; estimateSize?: number | undefined; } | undefined为大型列表启用虚拟化。注意:启用后,由于 Reka UI 的限制 (https://github.com/unovue/reka-ui/issues/1885).
|
valueKey | 'code' | "code"当 |
labelKey | 'name' | "name" | "code" | "dir" | "messages" | `messages.${string}`当 |
描述键 | 'description' | "name" | "code" | "dir" | "messages" | `messages.${string}`当 |
高亮 | boolean高亮环形颜色,如同焦点状态。 | |
createItem | false | boolean | "always" | { position?: "top" | "bottom" ; when?: "empty" | "always" | undefined; } | undefined确定是否可以添加选项中不存在的自定义用户输入。
|
filterFields | [labelKey] | string[]用于过滤项目的字段。 |
ignoreFilter | false | boolean当 |
autofocusDelay | number | |
前置 | boolean当为 | |
leadingIcon | any在左侧显示图标。 | |
尾部 | boolean当为 | |
loadingIcon | appConfig.ui.icons.loading | any当 |
ui | { base?: ClassNameValue; leading?: ClassNameValue; leadingIcon?: ClassNameValue; leadingAvatar?: ClassNameValue; leadingAvatarSize?: ClassNameValue; trailing?: ClassNameValue; trailingIcon?: ClassNameValue; value?: ClassNameValue; placeholder?: ClassNameValue; arrow?: ClassNameValue; content?: ClassNameValue; viewport?: ClassNameValue; group?: ClassNameValue; empty?: ClassNameValue; label?: ClassNameValue; separator?: ClassNameValue; item?: ClassNameValue; itemLeadingIcon?: ClassNameValue; itemLeadingAvatar?: ClassNameValue; itemLeadingAvatarSize?: ClassNameValue; itemLeadingChip?: ClassNameValue; itemLeadingChipSize?: ClassNameValue; itemTrailing?: ClassNameValue; itemTrailingIcon?: ClassNameValue; itemWrapper?: ClassNameValue; itemLabel?: ClassNameValue; itemDescription?: ClassNameValue; input?: ClassNameValue; focusScope?: ClassNameValue; } |