关于vue的UI框架Element,多层嵌套v-for循环下的表单验证

2 篇文章 0 订阅
1 篇文章 0 订阅

以下为一层嵌套

<el-form-item  v-for="(item,itemIndex) in form.button" :key="item.itemIndex"  label="一级菜单" >
        <el-form-item  :prop="'button.'+ itemIndex + '.name'" :rules="rules.inputTxt">
                <el-input v-model="item.name" style="width:200px;"></el-input>
        </el-form-item>
</el-form-item>

以下为两层,承接上一层的循环

<div v-for="(button,index) in item.sub_button" :key="button.index">
     <el-form-item  :prop="'button.'+ itemIndex +'.sub_button.'+ index + '.name'" :rules="rules.inputTxt" >
               <el-input v-model="button.name" style="width:200px;"></el-input>
        </el-form-item>
        <el-form-item  :prop="'button.'+ itemIndex +'.sub_button.'+ index + '.key'" :rules="rules.inputTxt" >
               <el-input v-model="button.key" style="width:200px;"></el-input>
        </el-form-item>
</el-form-item>

踩坑点
1,prop属性变成动态绑定的 :prop,
2,每一值外面都需要嵌套一层el-form-item,用来绑定prop的值还有 rules
3,:prop="‘button.’+ itemIndex + ‘.name’" 不能直接写成:prop=“item.name” ,
一定要写成循环的数组的真实的名字,用item是无法指向到对应的值的

  • 8
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值