element表格+表单+表单验证结合运用

目录

一、结果展示

二、实现代码


一、结果展示

1、图片

2、描述

table中放form表单,放输入框或下拉框或多选框等;

点击添加按钮,首先验证表单,如果存在没填的就验证提醒,都填了就向下添加一行表单表格;

点击当前行删除按钮,清除行。

二、实现代码

 <el-form :model="formother" ref="paramsForm" :rules="tablerule">
        <el-table :data="formother.customerAddressList" border style="width: 100%;">
          <el-table-column prop="consignee" label="收货人">
            <template slot-scope="scope">
              <el-form-item :prop="`customerAddressList[${scope.$index}].consignee`" 
               :rules=" [{ required: true, message: '请输入收货人', trigger: 'blur' }]">
            <el-input v-model="scope.row.consignee" placeholder="请输入收货人"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="phone" label="联系电话">
            <template slot-scope="scope">
              <el-form-item :prop="`customerAddressList[${scope.$index}].phone`"
                :rules="[{ required: true, message: '请输入联系电话', trigger: 'blur' }]">
             <el-input v-model="scope.row.phone" placeholder="请输入联系电话"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="address" label="收货地址">
            <template slot-scope="scope">
              <el-form-item :prop="`customerAddressList[${scope.$index}].address`"
                :rules="[{ required: true, message: '请输入收货地址', trigger: 'blur' }]">
            <el-input v-model="scope.row.address" placeholder="请输入收货地址"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="warehouse" label="仓库名称">
            <template slot-scope="scope">
              <el-form-item :prop="`customerAddressList[${scope.$index}].warehouse`"
                :rules="[{ required: true, message: '请输入仓库名称', trigger: 'blur' }]">
          <el-input v-model="scope.row.warehouse" placeholder="请输入仓库名称"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="100">
            <template slot-scope="scope">
              <el-button type="danger" icon="el-icon-delete" size="mini"
                @click="deleteParams(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
       </el-table>
  </el-form>
    addAddress() {
      this.$refs['paramsForm'].validate(vaild => {
        if (!vaild) return;
        this.formother.customerAddressList.push({
          consignee: "",
          phone: "",
          address: "",
          warehouse: ""
        })
      })
    },
    deleteParams(index) {
      this.formother.customerAddressList.splice(index, 1)
    }

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值