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

elementUI表达自定义校验,校验在v-for中

注意:本帖为公开技术贴,不得用做任何商业用途

<el-form :inline="true" :rules="rules" :model="formData" ref="formRef" class="mt-[20px]"><el-form-item label="选择区域" prop="area"><el-select v-model="formData.area" placeholder="请选择" @change="areaChange"><el-option v-for="item in areaList" :key="item.value" :label="item.name" :value="item.value"></el-option></el-select></el-form-item><el-row v-for="(item, index) in formData.content" :key="index" class="my-[20px]"><div><div class="mb-[10px]">{{ item.name }}:</div><divclass="border w-[400px] p-[10px] min-h-[45px]"style="border-radius: 5px; white-space: normal; word-break: break-all; border-color: #47536b"text="[14px]"@click="choiceSensor(item.name, item.ids)">{{ item.ids ? item.ids : "点击选择传感器" }}</div></div><div class="ml-[10px] flex items-center"><el-form-itemlabel="取值方式":prop="`content[${index}].valueWay`"style="margin-bottom: 0; margin-top: 20px":rules="[{ required: true, message: '请选择', trigger: 'blur' }]"><el-select v-model="item.valueWay" placeholder="请选择"><el-option v-for="item in valueWayList" :key="item.value" :label="item.name" :value="item.value"></el-option></el-select></el-form-item><el-form-itemlabel="环境阈值":prop="`content[${index}].threshold`"style="margin-bottom: 0; margin-top: 20px":rules="[{ required: true, message: '请输入环境阈值', trigger: 'blur' },{ pattern: rule0_1, message: '请输入大于等于1的1位小数', trigger: 'blur' },]"><el-input v-model="item.threshold" placeholder="环境阈值" /></el-form-item><el-form-itemlabel="浮动值":prop="`content[${index}].floating`"style="margin-bottom: 0; margin-top: 20px":rules="[{ required: true, message: '请输入环境阈值', trigger: 'blur' },{ pattern: rule0_1, message: '请输入大于等于1的1位小数', trigger: 'blur' },]"><el-input v-model="item.floating" placeholder="浮动值" /></el-form-item></div></el-row></el-form>

这里ts/js部分

const formRef = ref();
// 保留大于等于0的1位小数
export const rule0_1 = /^(0|[1-9]\d*)(\.\d)?$/
const formData = ref<any>({area: "",content: [{ name: "温度", ids: "", valueWay: "", threshold: "", floating: "", rule: rule0_1 }, // 温度{ name: "湿度", ids: "", valueWay: "", threshold: "", floating: "", rule: rule0_1 }, // 湿度{ name: "co", ids: "", valueWay: "", threshold: "", floating: "", rule: rule0_1 }, // co{ name: "co2", ids: "", valueWay: "", threshold: "", floating: "", rule: rule0_1 }, // co2{ name: "照度", ids: "", valueWay: "", threshold: "", floating: "", rule: rule0_1 }, // 照度{ name: "PM2.5", ids: "", valueWay: "", threshold: "", floating: "", rule: rule0_1 }, // PM2.5],
});

其中取值方式,环境阈值,浮动值,均在循环中完成,自定义的的表单校验,同类型同一种校验

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

相关文章:

  • Elasticsearch 在linux部署 及 Docker 集群部署详解案例示范
  • 短信验证码发送实现(详细教程)
  • P450催化的联芳基偶联反应-文献精读72
  • 在不支持AVX的linux上使用PaddleOCR
  • Python数据分析——Numpy
  • JMeter快速入门示例
  • 【333基于Java Web的考编论坛网站的设计与实现
  • 计算机网络关键名词中英对照
  • 二叉树的学习
  • 免费开源的医疗信息提取系统:提升超声波影像的诊断价值
  • Bash 中的 ${} 和 $() 有什么区别 ?
  • SPSS、R语言因子分析FA、主成分分析PCA对居民消费结构数据可视化分析
  • 高级SQL技巧掌握
  • 数组实例之三子棋的实现(C语言)
  • 【Linux驱动开发】设备树节点驱动开发入门
  • C++——string的模拟实现(下)
  • 面试 Java 基础八股文十问十答第二十九期
  • 454.四数相加||
  • 禅道源码部署
  • ️ Vulnhuntr:利用大型语言模型(LLM)进行零样本漏洞发现的工具
  • 【Android】多渠道打包配置
  • Spring Boot Configuration和AutoConfiguration加载逻辑和加载顺序调整
  • 点餐系统需求分析说明书(软件工程分析报告JAVA)
  • Python条形图 | 指标(特征)重要性图的绘制
  • 危险物品图像分割系统:一键训练
  • 城市景色视频素材下载好去处
  • 基于SSM美容院管理系统的设计
  • Threejs 实现3D 地图(04)3d 地图的柱状图和文字显示
  • Oracle 第2章:安装与配置Oracle
  • 动态规划 —— 斐波那契数列模型-解码方法