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

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>
            <div
              class="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-item
              label="取值方式"
              :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-item
              label="环境阈值"
              :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-item
              label="浮动值"
              :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.kler.cn/news/367701.html

相关文章:

  • ELK日志收集
  • 【AI绘画】Midjourney进阶:对角线构图详解
  • Redis 事务 总结
  • 2024系统架构师---真题考试知识点
  • UML 总结(基于《标准建模语言UML教程》)
  • axure中继器
  • MySQL笔试面试题之AI答(2)
  • ubuntu 安装k3s
  • Centos7.6版本安装mysql详细步骤
  • 基于大数据 Python Vue 美食推荐可视化系统(源码+LW+部署讲解+数据库)
  • GAMES101------学习笔记---自用02--Antialiasing (反走样)
  • ProtoBuf初识及其安装
  • Python流程控制专题:循环与else
  • Open WebUI + openai API / vllm API ,实战部署教程
  • Zookeeper面试整理-故障排查和调试
  • 【Linux】线程池详解及其基本架构与单例模式实现
  • 如何高效集成聚水潭数据至MySQL-技术案例解析
  • offset Explorer连接云服务上的kafka连接不上
  • CRM与OA:企业选择哪个更适合?
  • 带电脑在外出差,可以将电脑屏幕投屏到家里的电视吗?
  • 精益思维在新能源汽车研发中的应用体现
  • 应对.baxia勒索病毒挑战:数据恢复与预防措施并重
  • 抖动(Thrashing)
  • 数据挖掘(三)
  • 【OSlab】qemu和AbstractMachine的使用
  • 504 Gateway Time-outopenresty