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

相关推荐
林恒smileZAZ6 小时前
用 Vue 3 + Electron 做桌宠:从启动退出到拖拽、单击与鼠标穿透
vue.js·electron·计算机外设
软件技术NINI7 小时前
基于JavaWeb 汽车租聘
java·vue.js·spring boot·后端·python·毕业设计·毕设
2301_322414280414 小时前
基于SpringBoot+Vue的休闲零食超市管理系统的设计与实现59004-计算机毕设 原创(免费领源码+部署教程+开发环境)
java·vue.js·spring boot·redis·mysql·决策树·推荐算法
酷炫码神20 小时前
Day 8|Vue3 响应式:告别手动操作 DOM,让数据驱动界面
javascript·vue.js·ecmascript
星光不问赶路人1 天前
Vue 3 对象监听与快照:ref 和 reactive 的关键差异
前端·vue.js
稻草人4781 天前
Vue3.0项目创建步骤
vue.js
Bug收容所1 天前
Vue+js Day2
前端·javascript·vue.js
honkun61 天前
vue 下拉树组件 vxe-table-select 实现分页多选
前端·javascript·vue.js
溪语流沙1 天前
【Web全栈进阶】监控与告警:线上系统的“体检报告”
前端·vue.js·python·fastapi
卤蛋fg61 天前
vue 下拉树组件 vxe-table-select 实现分页多选
vue.js