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

相关推荐
用户45141942932220 分钟前
2026 Vue 生态分析:底层重写了一遍,升级却几乎零成本
vue.js
tryCbest1 小时前
Vue系列——第 20 篇:Vue Router 4——路由管理完全指南(上)
前端·javascript·vue.js
用户841794814563 小时前
vue 表格组件 vxe-table 实现 Excel 双击填充柄向下复制填充功能
vue.js
徐小夕9 小时前
深度拆解 Design Agent:LangChain 出品,AI 设计从「好看」走向「可用」
前端·vue.js·github
1-1=010 小时前
Vue 表单数据和过滤器
前端·javascript·vue.js
头发还在的女程序员11 小时前
智慧物业源码解析:房屋档案与业主变更怎样保持历史业务连续
前端·javascript·vue.js·物业管理·小区物业·智慧物业
某哈压力大1 天前
移动端 rem 适配
前端·vue.js·面试
洋洋技术笔记1 天前
动态组件与异步组件
vue.js
程序员大阳1 天前
副队长Vue3教程(5)--事件绑定 v-on
前端·javascript·vue.js·vue3·事件绑定·v-on
OpenTiny社区1 天前
我用Vue 100%复制DeepSeek开源的网页App,代码更少,功能还更多!
前端·vue.js·github