vxe-select 下拉框实现带单选框/复选框勾选功能

在使用下拉选择组件时,有时需要在选项前显示单选框或复选框,以明确多选/单选的操作感。vxe-select 提供了 show-radio 和 show-checkbox 属性,可以轻松实现带勾选框的下拉选择。

单选框

通过 show-checkbox显示单选框

html 复制代码
<template>
  <div>
    <vxe-select v-model="val1" v-bind="selectOptions"></vxe-select>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'

const val1 = ref()

const selectOptions = reactive({
  clearable: true,
  showRadio: true,
  options: [
    { value: 1001, label: 'table' },
    { value: 1002, label: 'grid' },
    { value: 1003, label: 'button' },
    { value: 1004, label: 'toolbar' },
    { value: 1005, label: 'tooltip' },
    { value: 1006, label: 'pager' },
    { value: 1007, label: 'print' },
    { value: 1008, label: 'export' },
    { value: 1009, label: 'import' },
    { value: 1010, label: 'select' },
    { value: 1012, label: 'checkbox' },
    { value: 1013, label: 'group' }
  ]
})
</script>

复选框

通过 show-checkbox显示复选框

html 复制代码
<template>
  <div>
    <vxe-select v-model="val1" v-bind="selectOptions"></vxe-select>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'

const val1 = ref([])

const selectOptions = reactive({
  clearable: true,
  multiple: true,
  showCheckbox: true,
  options: [
    { value: 1001, label: 'table' },
    { value: 1002, label: 'grid' },
    { value: 1003, label: 'button' },
    { value: 1004, label: 'toolbar' },
    { value: 1005, label: 'tooltip' },
    { value: 1006, label: 'pager' },
    { value: 1007, label: 'print' },
    { value: 1008, label: 'export' },
    { value: 1009, label: 'import' },
    { value: 1010, label: 'select' },
    { value: 1012, label: 'checkbox' },
    { value: 1013, label: 'group' }
  ]
})
</script>

说i吗

  • show-radio 只对单选场景有效,show-checkbox只对对选场景有效
  • 若下拉选项较多,可配合 filterable(可搜索)提升体验。

vxeui.com

相关推荐
小小编程路2 小时前
C++ 块作用域详解:从基础到实战
前端·javascript·vue.js
虚惊一场2 小时前
MarkView:纯前端 Markdown 实时预览工具的架构设计
前端·javascript·vue.js
早期的虫儿有鸟吃3 小时前
Vue3
前端·javascript·vue.js
早期的虫儿有鸟吃4 小时前
vue2Day06----路由
前端·javascript·vue.js
阿黎梨梨4 小时前
从敲下回车到文字逐字出现:AI 流式输出的前端必修课
vue.js·人工智能
小林ixn4 小时前
Vue3接入DeepSeek流式输出,把“二进制碎片”和“局部热更新”扒个精光
前端·vue.js·人工智能
Cobyte5 小时前
编译解析器的基础——状态模式与状态机的原理
前端·javascript·vue.js
Listen·Rain6 小时前
Vue3中computed详解
前端·javascript·vue.js
鱼樱前端16 小时前
别再自己拼凑了!这款 Vue 3.5+ 严肃产品级组件库,把 AI 对话、工作流和复杂数据全包了!
javascript·vue.js·github
Listen·Rain17 小时前
Vue3:setup详解
前端·javascript·vue.js