el-table 前端自定义的列表添加和删除

1.前端自定义的列表添加和删除

 <el-form ref="formData" :rules="formRules" :model="ruleForm" label-width="200px" >
          <el-form-item label="要求内容:" prop="infoArrayDTOList">
            <el-button type="text"  @click="handleAdd('内容')">添加</el-button>
            <el-table :data="formData.infoArrayDTOList" height="300" class="box" :header-cell-style="{ background: 'rgb(242, 242, 242)' }" row-key="id" border fit highlight-current-row style="margin-top: 10px;">
           
              <el-table-column type="index" label="序号" width="50" align="center"> </el-table-column>
              <el-table-column  prop='ruleName' label='信息' align="center" :render-header="addRedStar">
                <template slot-scope="scope">
                  <el-form-item :prop="'infoArrayDTOList.' + scope.$index + '.ruleName'" :rules="formRules.ruleName">
                    <el-input v-model="scope.row.ruleName" />
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column  prop='jobPosition' label='岗位' align="center" :render-header="addRedStar">
                <template slot-scope="scope">
                  <el-form-item :prop="'infoArrayDTOList.' + scope.$index + '.jobPosition'" :rules="formRules.jobPosition">
                    <el-select v-model="scope.row.jobPosition" multiple clearable placeholder="请选择" style="width:100%">
                      <el-option label="区域一" value="shanghai"></el-option>
                      <el-option label="区域二" value="beijing"></el-option>
                      </el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="" label="操作" align="center" width="80">
                <template slot-scope="scope">
                  <el-button type="text" size="mini" :disabled="formTitleTip!='add'" @click.native.prevent="handleDelete('内容',scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
</el-form >
formData:{
infoArrayDTOList:[],
},
formRules:{
  contractOppositeName: [
      { required: true, message: "不能为空", trigger: "blur" },
      { max: 20, message: "20字以内", trigger: "blur" },
  ],
  jobPosition: [
       { required: true, message: "不能为空", trigger: "blur" },
       { max: 20, message: "20字以内", trigger: "blur" },
 ],
},

    handleAdd(val) {
      let obj = {
        ruleName: "",
        jobPosition: "",
      };
      if (val == "内容") {
        this.formData.infoArrayDTOList.push(obj);
      }
    },
  //删除行
    handleDelete(val, index) {
      if (val == "内容") {
        this.formData.infoArrayDTOList.splice(index, 1);
      }
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值