工作笔记:elementUI实现数组(需要验证的数据是以数组的形式呈现)表单验证

<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("")

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值