Skip to content

Header

示例

基本使用

<template>
  <div>
    <SuperSelect v-model="value" :options="options" width="200px"></SuperSelect>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref()
const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

leable添加前缀

<template>
  <div>
    <SuperSelect v-model="value" :options="options" width="200px" prefix></SuperSelect>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref()
const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

对象类型数据

<template>
  <div>
    <SuperSelect v-model="value" :options="options" width="200px" valueIsObject></SuperSelect>
    <div>value选中的值: {{ value }}</div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref()
const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

禁用状态

<template>
  <div>
    <div>全部禁用</div>
    <SuperSelect v-model="value" :options="options" width="200px" disabled></SuperSelect>
    <div>选项禁用</div>
    <SuperSelect v-model="value" :options="options" width="200px" :disabled="isDisabled"></SuperSelect>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref()
const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]

const isDisabled = (item: { value: string }) => {
  return item.value === '2'
}
</script>

多选功能

<template>
  <div>
    <SuperSelect v-model="value" :options="options" multiple width="200px"></SuperSelect>
    <div>value选中的值: {{ value }}</div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref()
const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

多选添加添加全选按钮

<template>
  <div>
    <div>添加全选按钮</div>
    <SuperSelect
      v-model="value"
      :options="options"
      width="200px"
      multiple
      hasCheckAll
      valueIsObject
    ></SuperSelect>
    <div>未添加全选按钮</div>
    <SuperSelect
      v-model="value"
      :options="options"
      width="200px"
      multiple
      valueIsObject
    ></SuperSelect>

    <div>value选中的值: {{ value }}</div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref([])
const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

collapse-tags 和 collapse-tags-tooltip 多选功能

<template>
  <div>
    <div>collapse-tags</div>
    <SuperSelect
      v-model="value"
      :options="options"
      multiple
      collapse-tags
      hasCheckAll
      width="200px"
    ></SuperSelect>
    <div>collapse-tags + collapse-tags-tooltip</div>
    <SuperSelect
      v-model="value"
      :options="options"
      multiple
      collapse-tags
      collapse-tags-tooltip
      hasCheckAll
      width="200px"
    ></SuperSelect>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref()
const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
  { label: '选项4', value: '4' },
  { label: '选项5', value: '5' },
  { label: '选项6', value: '6' },
]
</script>

虚拟列表

<template>
  <div>
    <SuperSelect
      v-model="value"
      useVirtual
      :options="options"
      width="200px"
    ></SuperSelect>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value = ref()

const initials = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
const options = ref(
  Array.from({ length: 1000 }).map((_, idx) => ({
    value: `Option ${idx + 1}`,
    label: `${initials[idx % 10]}${idx}`,
  })),
)
</script>

API

Props

参数说明类型可选值默认值
modelValue绑定值string | number | Array<any> | Record<string, any> --
useVirtual是否使用虚拟列表booleantrue | falsefalse
options选项数据源Array<any>--
labelKey自定义label字段属性名string-label
valueKey自定义value字段属性名string-value
prefix是否使用前缀boolean | ((item: any) => boolean)--
disabled是否禁用boolean | ((item: any) => boolean)--
filterable是否可搜索booleantrue | falsefalse
hasCheckAll是否显示全选booleantrue/falsefalse
valueIsObject值是否为对象booleantrue/falsefalse

Slots

插槽名说明
header下拉列表顶部的内容