el-table表格每一行输入框之间的数字校验比较

1、表部分

<el-table-column prop="outdepot_quantity" label="测试字段" min-width="35%">
              <template slot-scope="scope">
                <el-form-item style="padding-top: 25px" :error="scope.row.outdepotQuantityError">
                  <el-input v-model="scope.row.outdepot_quantity" clearable @blur="outdepotQuantityValidate(scope.row)"></el-input>
                </el-form-item>
              </template>
</el-table-column>

2、验证函数

outdepotQuantityValidate(row) {
        //库存数量验证
        let pattern = /^[1-9][0-9]*([\.][0-9]{1,9})?$/
        this.$set(row, 'outdepotQuantityError', null)
        if (row.outdepot_quantity > row.instock_quantity) {
          this.$set(row, 'outdepotQuantityError', 'xxx数量不能大于xxx数量')
        } else if (!pattern.test(row.outdepot_quantity)) {
          this.$set(row, 'outdepotQuantityError', '请输入正确的输入数据格式')
        }
      },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于 `el-table` 表格中的输入框字段进行校验,可以通过以下步骤实现: 1. 在表格中将要进行校验的字段设置为可编辑的输入框,并绑定一个 `v-model` 指令,用于实时获取输入框的值。 2. 在需要校验的时候,通过正则表达式或其他方式校验输入框的值是否符合要求。 3. 如果输入框的值不符合要求,可以通过 `this.$message` 提示用户输入不合法,并将输入框的值重置为之前的值或者让用户重新输入。 以下是一个简单的示例代码,以手机号码为例进行校验: ```html <template> <el-table :data="tableData" style="width: 100%"> <el-table-column label="姓名" prop="name"></el-table-column> <el-table-column label="手机号码" prop="phone"> <template slot-scope="{ row }"> <el-input v-model="row.phone" @blur="checkPhone(row)"></el-input> </template> </el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ { name: '张三', phone: '13888888888' }, { name: '李四', phone: '13999999999' }, { name: '王五', phone: '13000000000' } ] } }, methods: { checkPhone(row) { const reg = /^1[3-9]\d{9}$/ // 手机号码正则表达式 if (!reg.test(row.phone)) { this.$message.error('请输入正确的手机号码') row.phone = '' // 重置输入框的值 } } } } </script> ``` 在上面的示例代码中,通过在 `el-input` 组件上绑定 `@blur` 事件,在输入框失去焦点时触发校验手机号码的方法 `checkPhone`。如果手机号码不符合要求,通过 `this.$message` 提示用户输入不合法,并重置输入框的值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值