表单验证、属性绑定(一个属性根据另一个属性有无进行操作)

news/2024/7/8 2:53:35

表单验证 一个属性根据另一个属性有无进行操作(属性绑定)

1、问题描述

需求:表单里面后两个属性需要根据前面一个属性进行有无判断。如果前面属性没有输入值,则不需要进行操作;如果前面属性有输入值,则后面两个值都需要进行填入。即前面不选,则后必选。

包含:表单验证、属性绑定、整体表单验证

最后样式

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

<el-form
    ref="ruleForm"
    :rules="formRules"
    :model="tableData"
    >
    <el-table
      border="true"
      :show-header="false"
      :data="tableData"
    >
      <el-table-column
        label="节点参数"
        prop=""
        align="center"
        min-width="150"
      >
        <template #default="scope">
          {{ tabelText.node_param }}
        </template>
      </el-table-column>
      <el-table-column
        prop="param"
        align="center"
        min-width="150"
      >
        <template #default="scope">
          <el-input v-model="scope.row.param" />
        </template>
      </el-table-column>
      <el-table-column
        label="参数值符号"
        prop=""
        align="center"
        min-width="150"
      >
        <template #default="scope">
          {{ tabelText.node_symbol }}
        </template>
      </el-table-column>
      <el-table-column
        prop="operate"
        align="center"
        min-width="150"
      >
        <template #default="scope">
          <el-form-item
            prop="operate"
            :rules="(scope.row.param && !scope.row.operate) ? [{required: true, message: '请输入参数值', trigger: 'blur'}]:[{required:false}]"
          >
            <el-select
              v-model="scope.row.operate"
              class="m-2"
              placeholder="Select"
              style="width:100px"
              clearable
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
        label="参数值"
        prop=""
        min-width="150"
        align="center"
      >
        <template #default="scope">
          {{ tabelText.node_val }}
        </template>
      </el-table-column>
      <el-table-column
        prop="param_val"
        min-width="150"
        align="center"
      >
        <template #default="scope">
          <el-form-item
            prop="param_val"
            :rules="(scope.row.param && !scope.row.param_val) ? [{required: true, message: '请输入参数值', trigger: 'blur'}]:[{required:false}]"
          >
            <el-input v-model="scope.row.param_val" />
          </el-form-item>
        </template>
      </el-table-column>
    </el-table>
 </el-form>

<script setup>
const ruleForm = ref(null)
// 表单验证
const formRules = ref({})

// 整个表单验证
const createJudgeForm = () => {
  ruleForm.value.validate((valid) => {
    if (valid) {
      createView()
    } else {
      ElMessage({
        type: 'error',
        message: '表单验证失败'
      })
    }
  })
}
</script>

http://lihuaxi.xjx100.cn/news/2058214.html

相关文章

C#中处理文件的类以及应用程序配置文件简介

文章目录 一、C#中处理文件的类介绍二、应用程序配置文件应用程序配置文件的用途&#xff1a;如何使用配置文件&#xff1a; 一、C#中处理文件的类介绍 在C#中&#xff0c;处理文件的通用类是System.IO.File&#xff0c;它提供了一系列静态方法&#xff0c;可用于创建、复制、…

用stream流将list转为map

用stream流将list转为map 1、将list转为Map<Long, List> 按照spaceId分组&#xff0c;spaceId相同的为一组数据&#xff1a; List<BasEvaluationPriceResultDto> list new ArrayList(); Map<Long, List<BasEvaluationPriceResultDto>> priceResult…

一个类的名字后缀有Handler的都是有什么作用?

在Java中&#xff0c;类名后缀为"Handler"通常表示该类是一个处理器&#xff08;Handler&#xff09;。处理器是用来处理特定任务或事件的组件&#xff0c;通常在事件驱动的编程中使用。这种命名惯例在许多框架和库中都很常见&#xff0c;其中一些常见的用法包括&…

递归法解决多重背包问题

多重背包问题同样是01背包问题的变种&#xff0c;同样可以通过修改01背包部分代码来求解。 方法一&#xff1a;修改递归函数&#xff0c;根据题目新的限制条件——使用次数扩充状态参数个数&#xff0c;将同一个物品选用的次数同样作为参数传递到栈空间中&#xff0c;同时也对…

linux-c时间定时器函数timerfd

timerfd是Linux为用户程序提供的一个定时器接口。这个接口基于文件描述符&#xff0c;通过文件描述符的可读事件进行超时通知&#xff0c;所以能够被用于select/poll的应用场景。 ​ int timerfd_create(intclockid, intflags);int timerfd_settime(intfd, intflags, const st…

Win10共享打印机提示没有权限使用网络资源怎么办?

win10已共享打印机但别电脑找不到该怎么办&#xff1f;我们来看看解决方法&#xff0c;打开控制面板后点击程序与功能&#xff0c;点击启用或关闭Windows功能&#xff0c;勾选SMB文件共享支持功能即可&#xff0c;具体的操作步骤如下&#xff1a; 进入程序与功能 进入WIN10系统…

matplotlib.animation 3d姿态动画

目录 演示效果&#xff1a; 演示代码&#xff1a; 保存为gif 演示效果&#xff1a; 演示代码&#xff1a; import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib.animation import FuncAnimation# 定义人体关键点…

Talk|卡内基梅隆大学熊浩宇:Open-world Mobile Manipulation-开放世界机器人学习系统

本期为TechBeat人工智能社区第575期线上Talk。 北京时间2月29日(周四)20:00&#xff0c;卡内基梅隆大学研究生—熊浩宇的Talk已准时在TechBeat人工智能社区开播&#xff01; 他与大家分享的主题是: “Open-world Mobile Manipulation-开放世界机器人学习系统”&#xff0c;将向…