当前位置: 首页 > news >正文

vue el-radio-group多选封装及使用

基于Element UI库的Vue组件,实现了一个单选/多选框组合的效果,可以根据 type 属性的不同值来切换单选框(默认)和按钮式单选框/多选框。

创建组件index.vue (src/common-ui/radioGroup/index.vue)
<template><el-radio-groupv-model="hValue":size="size":disabled="disabled":text-color="textColor":fill="fill"><template v-for="(item, index) in dataSource"><el-radio-buttonv-if="type === 'button'":key="index":label="item[hProps.value]":disabled="item[hProps.disabled]":name="item[hProps.name]">{{ item[hProps.label] }}</el-radio-button><el-radiov-else:key="index+'else'":label="item[hProps.value]":disabled="item[hProps.disabled]":border="item[hProps.border] || border":size="item[hProps.size]":name="item[hProps.name]":class="{ vertical }">{{ item[hProps.label] }}</el-radio></template></el-radio-group>
</template><script>export default {name: "HRadioGroup",props: {border: Boolean,dataSource: {type: Array,label: [String, Number],value: [String, Number, Boolean],disabled: {type: Boolean,default: false},border: {type: Boolean,default: false},size: {type: String,validator(value) {return ["medium", "small", "mini"].indexOf(value) !== -1;}},name: String},disabled: {type: Boolean,default: false},fill: String,size: {type: String,validator(value) {return ["medium", "small", "mini"].indexOf(value) !== -1;}},textColor: String,type: {type: String,default: "normal",validator(value) {return ["normal", "button"].indexOf(value) !== -1;}},value: {type: [String, Number, Boolean]},vertical: Boolean,props: {type: Object,default() {return {};}}},computed: {hValue: {get() {return this.value;},set(value) {this.$emit("input", value);this.$emit("change", value);}},hProps() {return {label: "label",value: "value",disabled: "disabled",border: "border",size: "size",name: "name",...this.props};}}};
</script><style lang="scss" scoped>.vertical {display: block;margin-left: 0 !important;& + .vertical {margin-top: 10px;}}
</style>
页面引入
  • 在需要使用HRadioGroup组件的地方,通过import语句引入组件注册并使用

<template><div><h-radio-group:value="selectedValue":data-source="dataSource"@change="val => handleRadioGroupChange(val)"></h-radio-group></div>
</template>
<script>import HRadioGroup from '@/common-ui/radioGroup/index'export default {components: {HRadioGroup},data() {return {filterVal: '',dataSource: [],selectedValue: ''}},methods: {handleRadioGroupChange(val, row) {console.log(val,'选中的数据')},}// ...}
</script>

确保你已经安装了Vue.js和Element UI,并在项目中引入它们。

http://www.lryc.cn/news/250301.html

相关文章:

  • Kaggle-水果图像分类银奖项目 pytorch Densenet GoogleNet ResNet101 VGG19
  • TPLink-Wr702N 通过OpenWrt系统打造打印服务器实现无线打印
  • [UGUI]实现从一个道具栏拖拽一个UI道具到另一个道具栏
  • 微服务--08--Seata XA模式 AT模式
  • Doris 数据导入一:Broker Load 方式
  • docker踩坑记录:docker容器创建doris容器间无法通讯问题
  • springboot+java校园自助洗衣机预约系统的分析与设计ssm+jsp
  • TCP简介及特性
  • ElasticSearch 排障常用方法
  • 【SA8295P 源码分析 (四)】136 - QNX 如何抓取系统 log 方法 之 网络部分日志抓取方法
  • 传统算法:使用Pygame实现SVM(支持向量机)算法
  • cookie wzws_sess** 逆向
  • JIRA 基本使用
  • 什么是JVM的内存模型?详细阐述Java中局部变量、常量、类名等信息在JVM中的存储位置
  • c#学习相关系列之as和is的相关用法
  • excel合并单元格教程
  • img[src=““] img无路径情况下,页面出现边框
  • TA-Lib学习研究笔记(八)——Momentum Indicators 上
  • 【MATLAB源码-第91期】基于matlab的4QAM和4FSK在瑞利(rayleigh)信道下误码率对比仿真。
  • pywin32后台键鼠
  • 大屏适配方案(vw、vh)
  • 【QuickSort】单边快排思路及实现
  • C++:继承
  • 苍穹外卖--客户催单
  • 春秋云境:CVE-2022-32991(sql注入)
  • css实现鼠标移入背景图片变灰并浮现文字的效果
  • ES-深入理解倒排索引
  • linux NAT网卡配置static
  • 信奥编程 1168:大整数加法
  • k8s上Pod全自动调度、定向调度、亲和性调度、污点和容忍调度详解