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

相关推荐
farerboy2 小时前
WEB 项目如何禁用 F12 等功能
前端·vue.js·架构
parade岁月2 小时前
vtable-guild 被收录进 vuejs/awesome-vue 了 🎉
前端·vue.js
沙蒿同学2 小时前
一个人做完一套企业级系统,赚到了第一个 1000 块
vue.js·后端·go
mldong2 小时前
管理后台数据国际化:不建翻译表、一列 JSON、后端零改动
vue.js
Eric的技术杂货铺2 小时前
YsTable 使用:字典管理主从表页面完整实现(列配置、查询、权限按钮、主从联动、增删改查)
前端·vue.js
易朵朵2 小时前
package.json 中的 `vue-router` 详解
前端·vue.js
CopyCode2 小时前
ref、reactive、toRefs 到底该用哪个?我把三个反例都写了一遍
前端·vue.js
用户42528244567502 小时前
Vue3 复杂页面状态怎么管?别什么都往 Pinia 里塞了!
vue.js
牧艺2 小时前
cos-design 4.0:91 个特效组件一次捅成 React / Vue / Web Components / Core
前端·vue.js·web components
ikun_文2 小时前
Vue3框架项目初始化
vue.js·element·vue-router