<el-form :model="couponForm" ref="couponForm" label-width="200px">
<el-form-item v-for="(item,idx) in couponForm.actIdList" :label="'活动期间第' + (idx + 1) + '次下单得'" :prop="'actIdList['+idx+']'" :rules="{ required: true, message: '请选择'}">
<el-select
v-model="couponForm.actIdList[idx]"
filterable
placeholder="请选择">
<el-option v-for="(sItem,i) in couponList" :key="sItem.actId" :label="sItem.actName" :value="sItem.actId"></el-option>
</el-select>
<el-button type="text" @click="deleted(idx)" class="deleted">删除</el-button>
</el-form-item >
</el-form >
如上代码:
1.rules写到v-for元素中::rules="{ required: true, message: '请选择'}"
2.prop部分(我这里的actIdList为数组,所以不需要写属性;如果是对象,直接写成 :prop="'actIdList.'+idx+'.xx'")::prop="'actIdList['+idx+']'" 或者 :prop="'actIdList.'+idx"
3.v-modal部分:v-model="couponForm.actIdList[idx]",如果是对象,写成v-model="item.xx"
这样就可以实现,每个el-form-item都可以实现对应的验证
注:如果需要动态新增,直接新增couponForm.actIdList值就行:this.couponForm.actIdList.push("")