table中加表单元素怎么验证_el-table嵌入表单元素注意事项(验证规则prop写法与数据初始化)...

场景:在el-table表格中嵌入表单元素

绑定数据:

table :

:data="planFormData.allocationPlan"

el-form-item:

v-model="scope.row.shouldDisburseTotal"

表单验证规则:

el-form-item:

:prop="'allocationPlan.'+scope.$index+'.shouldDisburseTotal'":rules="rules.shouldDisburseTotal"

v-for循环生成表单元素

:prop写法如下

:prop="`methods[${i}].reduceScore`":rules="standardRules.reduceScore"label-width="0"style="display: inline-block; width: 150px"

>

v-model="v.reduceScore"style="width: 64px"

>

写法如下

1.data字段

planFormData: {

allocationTime:"",

allocationPlan: [],//拨付计划周期

},

2.页面元素

:data="planFormData.allocationPlan"id="allocationPlan"max-height="350px"border

v-loading="isLoading"style="width:960px;font-size:14px;color:#333333;margin-top:10px"

>

slot-scope="scope"

>{{scope.row.startDate}} 至 {{planFormData.allocationTime?scope.row.endDate:'(请选择拨付时间)'}}

v-if="scope.$index

>

v-model="scope.row.shouldDisburseTotal"@blur="checkLastCost"style="width:240px"class="table-input"

>

 元

注意点: 生成表格数据时,导致input框无法输入

dateArr.forEach((v, i) =>{//this.planFormData.allocationPlan[i] = {};

//this.planFormData.allocationPlan[i].startTime = v[0];

//this.planFormData.allocationPlan[i].endTime = v[1];

//this.planFormData.allocationPlan[i].shouldDisburseTotal = null;

)}

解决办法:

1.在data中的 planFormData.allocationPlan 对象数组 给出默认值

2.不要在数组循环时分别给表单元素绑定值,利用深拷贝给表单元素一次赋值

let planArr =[];

dateArr.forEach((v, i)=>{//planArr[i] = {};

planArr[i].startDate = v[0];

planArr[i].endDate= v[1];

planArr[i].shouldDisburseTotal= this.planFormData.allocationPlan[i].shouldDisburseTotal;

});this.planFormData.allocationPlan = JSON.parse(JSON.stringify(planArr));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值