vue+element ui 实现相互校验表单 前后 实时 校验两个输入框

标题 前后相互校验 实时输入实时校验

<el-form :rules="rules2" :model="form" ref="ruleForm2">
          <el-table
            ref="tableRef"
            :data="form.tableData"
            style="width: 100%"
            :cell-style="cellStyle"
            class="znv-table dark-table "
          >
            <el-table-column
              align="center"
              label="第一个数"
              prop="T1"
            >
              <template slot-scope="scope">
                <el-form-item
                  :prop="'tableData.' + scope.$index + '.T1'"
                  :rules="rules2.T1"
                  style="margin-top:10px"
                >
                  <el-input
                    v-model="scope.row.T1"
                    @blur="checkBlur(scope.$index)"
                    @input="form2CheckInput"
                  >
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="第二个数"
              prop="T2"
            >
              <template slot-scope="scope">
                <el-form-item
                  :prop="'tableData.' + scope.$index + '.T2'"
                  :rules="rules2.T2"
                  style="margin-top:10px"
                >
                  <el-input
                    v-model="scope.row.T2"
                    @blur="checkBlur(scope.$index)"
                    @input="form2CheckInput"
                  > 
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
 data() {
    let validateT1 = (rule, value, callback) => {
      let index = Number(rule.field.split(".")[1]);
      if (value < 13 || value > 30 || value == 13 ) {
        callback(new Error("14~30"));
      } else if (value > this.form.tableData[index].T2) {
        callback(new Error(this.$t("strategy[20]")));
      } else {
        callback();
      }
    };
    let validateT2 = (rule, value, callback) => {
      let index = Number(rule.field.split(".")[1]);
      if (value < 13 || value > 30) {
        callback(new Error("14~30"));
      } else if (value < this.form.tableData[index].T1) {
        callback(new Error(this.$t("strategy[21]")));
      } else {
        callback();
      }
    };
    rules2: {
        T1: [
          {
            required: true,
            message: this.$t("strategy[24]"),
            trigger: "change"
          },
          {
            validator: validateT1,
            trigger: "change"
          }
        ],
        T2: [
          {
            required: true,
            message: this.$t("strategy[24]"),
            trigger: "change"
          },
          {
            validator: validateT2,
            trigger: "change"
          }
        ],
     }
//方法中:
 	checkBlur() {},
    //实时校验表单内容更改
    form2CheckInput() {
      this.$refs.ruleForm2.validate()
    },
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

new Vue()

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值