Select V2 virtualized selector beta

TIP

这个组件目前在测试当中,如果在使用中发现任何漏洞和问题,请在 GitHub 中提交 issue 以便我们进行处理。

TIP

在 SSR 场景下,您需要将组件包裹在 <client-only></client-only> 之中 (如: Nuxt) 和 SSG (例如: VitePress).

背景

在某些使用情况下,单个选择器可能最终加载数万行数据。 将这么多的数据渲染至 DOM 中可能会给浏览器带来负担,从而造成性能问题。 为了更好的用户和开发者体验,我们决定添加此组件。

基础用法

适用广泛的基础选择器

多选

最基础的多选选择器

隐藏多余标签的多选

默认情况下选中值会以 Tag 的形式展现,你也可以设置collapse-tags属性将它们合并为一段文字。 您可以使用 collapse-tags-tooltip 属性来启用鼠标悬停折叠文字以显示具体所选值的行为。

可过滤的多选

当选项太多时,你可以使用 filterable 选项来启用过滤功能来找到所需的选项。

禁用选择器本身或选项

您可以选择禁用 Select 或者 Select 中的某个选项。

给选项进行分组

只要数据格式满足特定要求,我们就可以按照自己的意愿为选项进行分组。

自定义选项的渲染模板

我们也可以通过自定义模板来渲染自己想要的选项内容。

一键清除

我们可以同时清除所有选定的选项。此设定也适用于单选。

创建临时选项

创建并选中未包含在初始选项中的条目。

通过使用 allow-create 属性,用户可以通过输入框创建新项目。 为了使 allow-create 正常工作, filterable 的值必须为 true

TIP

最好在使用 allow-create 属性的同时设置 :reserve-keyword="false"

远程搜索

输入关键字以从远程服务器中查找数据。

Use value-key attribute

when options.value is an object, you should set a unique identity key name for value

TIP

Before 2.4.0, value-key was used both as the unique value of the selected object and as an alias for the value in options. Now value-key is only used as the unique value of the selected object, and the alias for the value in options is props.value.

Aliases for custom options 2.4.2

When your options format is different from the default format, you can customize the alias of the options through the props attribute

SelectV2 Attributes

属性名说明类型可选值默认值
model-value / v-model绑定值string / number / boolean / object
optionsdata of the options, the key of value and label can be customize by propsArray
props 2.4.2configuration options, see the following tableobject
multipleis multiplebooleanfalse
disabledis disabledbooleanfalse
value-keyunique identity key name for value, required when value is an objectstringvalue
sizeinput box sizestringlarge/default/smalldefault
clearablewhether select can be clearedbooleanfalse
clear-iconcustom clear iconstring | ComponentCircleClose
collapse-tagswhether to collapse tags to a text when multiple selectingbooleanfalse
multiple-limitmaximum number of options user can select when multiple is true. No limit when set to 0number0
namethe name attribute of select inputstring
effectTooltip theme, built-in theme: dark / lightstringstringlight
autocompleteautocomplete of select inputstringoff
placeholderplaceholderstringPlease select
filterableis filterablebooleanfalse
allow-createwhether creating new items is allowed. To use this, filterable must be truebooleanfalse
reserve-keywordwhether reserve the keyword after select filtered option.booleantrue
no-data-textdisplayed text when there is no options, you can also use slot emptystringNo Data
popper-classcustom class name for Select's dropdownstring
popper-append-to-body deprecatedwhether to append the popper menu to body. If the positioning of the popper is wrong, you can try to set this prop to falseboolean-false
teleportedwhether select dropdown is teleported to the bodybooleantrue / falsetrue
persistentwhen select dropdown is inactive and persistent is false, select dropdown will be destroyedbooleantrue / falsetrue
popper-optionsCustomized popper option see more at popper.jsobject--
automatic-dropdownfor non-filterable Select, this prop decides if the option menu pops up when the input is focusedboolean-false
heightThe height of the dropdown panel, 34px for each itemnumber-170
item-heightThe height of the dropdown itemnumber-34
scrollbar-always-onControls whether the scrollbar is always displayedboolean-false
remotewhether search data from serverbooleanfalse
remote-methodfunction that gets called when the input value changes. Its parameter is the current input value. To use this, filterable must be truefunction(keyword: string)
validate-eventwhether to trigger form validationboolean-true
placementposition of dropdownstringtop/top-start/top-end/bottom/bottom-start/bottom-end/left/left-start/left-end/right/right-start/right-endbottom-start
collapse-tags-tooltip 2.3.0whether show all selected tags when mouse hover text of collapse-tags. To use this, collapse-tags must be truebooleantrue / falsefalse
max-collapse-tags 2.3.0The max tags number to be shown. To use this, collapse-tags must be truenumber1

props

Attribute说明TypeDefault
valuespecify which key of node object is used as the node's valuestringvalue
labelspecify which key of node object is used as the node's labelstringlabel
optionsspecify which key of node object is used as the node's childrenstringoptions
disabledspecify which key of node object is used as the node's disabledstringdisabled

SelectV2 Events

插槽名说明Params
changetriggers when the selected value changescurrent selected value
visible-changetriggers when the dropdown appears/disappearstrue when it appears, and false otherwise
remove-tagtriggers when a tag is removed in multiple moderemoved tag value
cleartriggers when the clear icon is clicked in a clearable Select
blurtriggers when Input blurs(event: FocusEvent)
focustriggers when Input focuses(event: FocusEvent)

SelectV2 Slots

NameDescription
defaultOption renderer
emptycontent when options is empty
prefixprefix content of input