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

相关推荐
_xaboy10 小时前
开源Vue组件 FormCreate 使用组件内部方法校验
前端·vue.js·开源
Cobyte11 小时前
13.响应式系统演进:版本化动态依赖管理机制解析(Vue3.4)
前端·javascript·vue.js
ljt272496066112 小时前
Vue笔记(五)--组件进阶
前端·vue.js·笔记
桔筐12 小时前
【无标题】
前端·vue.js
智商不够_熬夜来凑1 天前
【Picker】单选多选
前端·javascript·vue.js
jaychouchannel1 天前
深入理解 Vue 3 Composition API:为什么它是现代前端的必修课
vue.js
笔优站长1 天前
从 Vue 2 到 Vue 3:我把 vue-aliplayer-v2 重构成了一个更现代的阿里云播放器组件
前端·vue.js
i_am_a_div_日积月累_1 天前
3.contextBridge桥梁
前端·javascript·vue.js·electron
bug-100861 天前
hooks,mixin,pinia,vuex
前端·vue.js