element-ui for循环生成表单,表单如何添加校验

ElementUI 中使用循环生成的form表单需要动态添加校验的规则
动态表单页面,需要把规则放在el-form-item中,进行校验

代码片段

         <div v-for="(allItem,index) in ruleForm.boothManagerValues" :key="index" style="display:flex;justify-content: flex-start;width: 600px;">
              <el-form-item
                label="落位经理:"
                :prop="'boothManagerValues.'+index+'.userId'"
                :rules="[ { required: true, message: '请选择落位经理', trigger: 'blur' }]"
              >

                <el-select
                  v-model="allItem.userId"
                  placeholder="请选择:"
                  style="width: 140PX"
                >
                  <el-option
                    v-for="item in managerList"
                    :key="item.id"
                    :label="item.surename"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item
                label="参展品类:"
                :prop="'boothManagerValues.'+index+'.categoryId'"
                :rules="[ { required: true, message: '请选择参展品类', trigger: 'blur' }]"
                style="margin-left: -20px;"
              >
                <el-cascader
                  ref="cascaderArr"
                  v-model="allItem.categoryId"
                  popper-class="theder"
                  style="width:140PX;"
                  :options="CategoryList"
                  :props="optionProps"
                  @change="categoryChange(index)"
                />
              </el-form-item>
              <span v-if="ruleForm.boothManagerValues.length===index+1" style="display:inline-block;height: 32px;width: 32px;line-height: 32px;text-align: center;border: 1px solid #DCDFE6;border-radius: 6px;font-size: 20px;    vertical-align: middle;margin-left: 10px;cursor: pointer;" @click="plus(index)">+</span>
              <span v-if="ruleForm.boothManagerValues.length===index+1" style="display:inline-block;height: 32px;width: 32px;line-height: 28px;text-align: center;border: 1px solid #DCDFE6;border-radius: 6px;font-size: 30px;    vertical-align: middle;margin-left: 10px;cursor: pointer;" @click="minus(index)">-</span>
            </div>

:prop=“‘boothManagerValues.’+index+‘.userId’”
:prop=“‘boothManagerValues.’+index+‘.categoryId’”

字段说明:
ruleForm.boothManagerValues是v-for绑定的数组,

index是索引主要定义不同的prop

userId和categoryId就是key值

效果如下:
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值