VEUI

VEUI on GitHub
Play!中文

Select

Examples

Size variants

Available ui prop values: xs / s / m / l.

请选择
请选择
请选择
请选择
Edit this demo on GitHubEdit
<template>
<article>
  <veui-select
    v-model="license"
    class="select"
    ui="l"
    :options="options"
  />
  <veui-select
    v-model="license"
    class="select"
    :options="options"
  />
  <veui-select
    v-model="license"
    class="select"
    ui="s"
    :options="options"
  />
  <veui-select
    v-model="license"
    class="select"
    ui="xs"
    :options="options"
  />
</article>
</template>

<script>
import { Select } from 'veui'

export default {
  components: {
    'veui-select': Select
  },
  data () {
    return {
      license: null,
      options: [
        {
          label: 'MIT',
          value: 'mit'
        },
        {
          label: 'BSD',
          value: 'bsd'
        },
        {
          label: 'Apache 2.0',
          value: 'apache2'
        }
      ]
    }
  }
}
</script>

<style lang="less" scoped>
.select {
  max-width: 120px;
  margin-right: 10px;
}
</style>

Inline options

Use the OptionGroup and Option components inside the Select component to replace the options prop.

Pick one...

Selected: -

clearable can be used to allow selected values to be discarded for Select. Set position of the inline OptionGroups to popup to display children options inside a popup menu.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-select
    v-model="item"
    class="select"
    placeholder="Pick one..."
    clearable
  >
    <veui-option-group
      label="Editors"
      position="popup"
    >
      <veui-option
        value="vscode"
        label="VSCode"
      />
      <veui-option
        value="sublime"
        label="SublimeText"
      />
      <veui-option
        value="atom"
        label="Atom"
      />
    </veui-option-group>
    <veui-option-group
      label="Browsers"
      position="popup"
    >
      <veui-option-group
        label="Desktop"
        position="popup"
      >
        <veui-option
          value="ie"
          label="IE"
        />
        <veui-option
          value="edge"
          label="Edge"
        />
        <veui-option
          value="firefox"
          label="Firefox"
        />
        <veui-option
          value="chrome"
          label="Chrome"
        />
      </veui-option-group>
      <veui-option-group
        label="Mobile"
        position="popup"
      >
        <veui-option
          value="ios_safari"
          label="iOS Safari"
        />
        <veui-option
          value="android"
          label="Android Browser"
        />
        <veui-option
          value="android_chrome"
          label="Chrome for Android"
        />
      </veui-option-group>
    </veui-option-group>
  </veui-select>
  <p>Selected: {{ item || '-' }}</p>
</article>
</template>

<script>
import { Select, OptionGroup, Option } from 'veui'

export default {
  components: {
    'veui-select': Select,
    'veui-option-group': OptionGroup,
    'veui-option': Option
  },
  data () {
    return {
      item: null
    }
  }
}
</script>

<style lang="less" scoped>
.select {
  width: 180px;
}
</style>

Searchable

Use the searchable prop to enable option search.

请选择
Edit this demo on GitHubEdit
<template>
<article>
  <veui-select
    v-model="license"
    :options="options"
    searchable
  />
</article>
</template>

<script>
import { Select } from 'veui'

export default {
  components: {
    'veui-select': Select
  },
  data () {
    return {
      license: null,
      options: [
        {
          label: 'MIT',
          value: 'mit'
        },
        {
          label: 'BSD',
          value: 'bsd'
        },
        {
          label: 'Apache 2.0',
          value: 'apache2'
        }
      ]
    }
  }
}
</script>

Multiple selection

Use the multiple prop to enable multiple selection mode.

请选择
0/5

Use max to specify the max number of options that can be selected. The searchable prop can also be used here to make options searchable.

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-checkbox v-model="searchable">
      Searchable
    </veui-checkbox>
  </section>
  <section>
    <veui-select
      v-model="license"
      multiple
      :options="options"
      :max="5"
      :searchable="searchable"
    />
  </section>
</article>
</template>

<script>
import { Select, Checkbox } from 'veui'

export default {
  components: {
    'veui-select': Select,
    'veui-checkbox': Checkbox
  },
  data () {
    return {
      searchable: false,
      license: null,
      options: [
        {
          label: 'MIT',
          value: 'mit'
        },
        {
          label: 'BSD',
          value: 'bsd'
        },
        {
          label: 'Apache 2.0',
          value: 'apache2'
        },
        {
          label: 'GPL 3.0',
          value: 'gpl3'
        },
        {
          label: 'AGPL 3.0',
          value: 'agpl3'
        },
        {
          label: 'LGPL 2.1',
          value: 'lgpl2'
        },
        {
          label: 'MPL 2.0',
          value: 'mpl2'
        }
      ]
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

Custom selected display

Use the label slot to customize how selected options are displayed when the dropdown is closed.

Use the selected slot to customize how selected options are displayed, regardless of whether the dropdown is closed.

下拉关闭时省略显示已选项

请选择

始终省略显示已选项

请选择
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <h4>下拉关闭时省略显示已选项</h4>
    <veui-select
      v-model="license"
      multiple
      :options="options"
    >
      <template
        #label="{ selected }"
      >{{ selected[0].label }}等{{ selected.length }}个{{ ' ' }}</template>
    </veui-select>
  </section>
  <section>
    <h4>始终省略显示已选项</h4>
    <veui-select
      v-model="license"
      multiple
      :options="options"
    >
      <template
        #selected="{ selected }"
      >{{ selected[0].label
      }}{{ selected.length > 1 ? `等${selected.length}个` : '' }}</template>
    </veui-select>
  </section>
</article>
</template>

<script>
import { Select } from 'veui'

export default {
  components: {
    'veui-select': Select
  },
  data () {
    return {
      searchable: false,
      license: null,
      options: [
        {
          label: 'MIT',
          value: 'mit'
        },
        {
          label: 'BSD',
          value: 'bsd'
        },
        {
          label: 'Apache 2.0',
          value: 'apache2'
        },
        {
          label: 'GPL 3.0',
          value: 'gpl3'
        },
        {
          label: 'AGPL 3.0',
          value: 'agpl3'
        },
        {
          label: 'LGPL 2.1',
          value: 'lgpl2'
        },
        {
          label: 'MPL 2.0',
          value: 'mpl2'
        }
      ]
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

API

Props

NameTypeDefaultDescription
uistring-

Predefined styles.

ValueDescription
xsExtra small size style.
sSmall size style.
mMedium size style.
lLarge size style.
optionsArray<Object>-

The option list, with items of type {label, value, options, disabled, ...}.

NameTypeDescription
labelstringThe text description of the option.
value*The value corresponding to the option.
optionsArray<Object>The array of child options for the option, with item types the same as the options prop array items.
disabledbooleanWhether the option is disabled.
valueArray<*>|*-

v-model

The selected value.

multiplebooleanfalseWhether to allow multiple selection.
maxnumber-The upper limit of items that can be selected in multiple selection mode.
placeholderstringselect.placeholderPlaceholder text when nothing is selected.
clearablebooleanfalseWhether the selected content can be cleared.
searchablebooleanfalseWhether to allow option search.
show-select-allbooleanfalseWhether to show the "Select All" option in multiple selection mode.
expandedbooleanfalse

.sync

Whether the dropdown menu is expanded.

disabledbooleanfalseWhether it is disabled.
readonlybooleanfalseWhether it is read-only.
compositionbooleanfalseWhether to perceive the value of input method input in the search box.
overlay-classstring | Array | Object-Refer to the overlay-class prop of the Overlay component.
overlay-stylestring | Array | Object-Refer to the overlay-style prop of the Overlay component.
match(item, keyword, { ancestors }) => boolean | [number, number] | Array<[number, number]>-Supports custom highlight logic, case-insensitive by default, refer to Autocomplete.
filter(item, keyword, { ancestors, offsets }) => boolean-Supports custom search hit logic, refer to Autocomplete.

Slots

NameDescription
defaultThe content of the option list. When the options property is not specified, it can be used to directly inline Option or OptionGroup.
before

The content before the option list. No default content.

NameTypeDescription
value*The value of the selected option.
selectfunction(value: *): voidUsed to switch the selected option.
expandedbooleanWhether the dropdown menu is expanded.
togglefunction(force?: boolean): voidUsed to toggle the dropdown menu expansion state.
afterThe content after the option list. No default content. Slot parameters are the same as the before slot.
label

The text area of the dropdown button.

Default content: The label property value of the selected option or the text content of the selected option in inline mode.

NameTypeDescription
labelstringThe text of the selected option.
value*The value of the selected option.
selectedbooleanWhether a value has been selected.
disabledbooleanWhether the option is disabled.

In addition, other properties in the current option data besides the above-described properties will also be automatically bound to the slot porps through v-bind.

group-label

The title text area of the dropdown option group (with options).

Default content: The label property value of the option.

NameTypeDescription
labelstringThe title text of the option group.
disabledbooleanWhether the option group is disabled.

In addition, other properties in the current option data besides the above-described properties will also be automatically bound to the slot porps through v-bind.

option-label

The text area of the dropdown option (without options).

Default content: The label property value of the option.

NameTypeDescription
labelstringThe text of the option.
value*The value of the option.
selectedbooleanWhether the option is selected.
disabledbooleanWhether the option is disabled.

In addition, other properties in the current option data besides the above-described properties will also be automatically bound to the slot porps through v-bind.

option

The entire area of the selectable dropdown option.

Default content: The default structure of the Option component.

NameTypeDescription
labelstringThe text of the option.
value*The value of the option.
selectedbooleanWhether the option is selected.
disabledbooleanWhether the option is disabled.

In addition, other properties in the current option data besides the above-described properties will also be automatically bound to the slot porps through v-bind.

trigger

The entire dropdown trigger area.

Default content: Dropdown button.

NameTypeDescription
attrsObjectThe attributes that need to be output to the trigger element, including aria-* / disabled, etc. You can use v-bind="attrs" to output them uniformly.
handlersObject

The event listeners that need to be bound to the trigger element can be output uniformly using v-on="handlers".

value*The value of the selected option.
selectfunction(value: *): voidUsed to switch the selected option.
expandedbooleanWhether the dropdown menu is expanded.
togglefunction(force?: boolean): voidUsed to toggle the expansion state of the dropdown menu.
selected

The selected value rendering area.

Default content: The label of the selected item is rendered for single selection; for multiple selection, the label of each selected item is rendered as a Tag component.

NameTypeDescription
labelstringThe option text.
value*The option value.
selectedbooleanWhether the option is selected.
disabledbooleanWhether the option is disabled.
NameTypeDescription
selectedArray<Object>An array of data for the selected items.
no-dataUsed to define the content to be displayed when there is no search data.

Events

NameDescription
inputTriggered when the search keyword is entered. The callback function takes (value: string) as the parameter, where value is the value of the input box.
change

v-model

Triggered when the selection state changes. The callback function takes (value: *) as the parameter, where value is the value of the value field of the currently selected option.

toggleTriggered when the drop-down menu's expanded state is toggled. The callback function takes (expanded: boolean) as the parameter. expanded indicates whether the operation will expand or collapse the drop-down menu.
clearTriggered when the clear button is clicked.
afteropenTriggered after the drop-down is opened.

Configs

KeyTypeDefaultDescription
select.placeholderstring@@select.placeholderPlaceholder content when nothing is selected.

Icons

NameDescription
expandExpand the overlay.
collapseCollapse the overlay.

CSS

NameTypeDefaultDescription
--dls-dropdown-max-display-items<integer>8

The maximum number of items to be displayed in the drop-down menu at the same time. The maximum height of the drop-down box will be calculated based on this value.

Edit this page on GitHubEdit
© Baidu, Inc. 2024