循环渲染的表单,添加字段校验,提交表单时判断校验结果,使用this.$refs[(“item” + index)].validate会报错
this.$refs[(“item” + index)].validate is not a function
需要这么使用:
this.$refs[“item”][0].validate
下面是项目中的代码:
html代码
<el-form
v-for="(item,index) in receiptInfoList"
:key="index"
:model="item"
:ref="'item'+index"
:rules="item.moneyRules"
label-width="0">
<el-row :gutter="10">
<el-col :lg="2" :sm="8">
<el-form-item :label="item.stageName" label-width="90px"></el-form-item>
</el-col>
<el-col :lg="4" :sm="8">
<el-form-item prop='estimatedReceivable'>
<el-input v-model="item.estimatedReceivable" :disabled="!item.editState"></el-input>
</el-form-item>
</el-col>
<el-col :lg="4" :sm="8">
<el-form-item>
<el-date-picker :disabled="!item.editState" type="date