<template slot-scope="scope"> <el-form-item :prop="'list.' + scope.$index + '.controlok'" :rules="fromDataRules.controlok" > <el-input v-if="scope.row.controluse === 'S2F21'" :disabled=" scope.row.iscontrol === false || scope.row.iscontrol == null || scope.row.iscontrol == '' " v-model="scope.row.controlok" filterable clearable /> <el-select v-else v-model="scope.row.controlok" :disabled=" scope.row.iscontrol === false || scope.row.iscontrol == null || scope.row.iscontrol == '' " :placeholder="t('web_ems_tip_pleaseInput')" filterable clearable > <el-option v-for="item in identifyingList" :key="item.id" :label="item" :value="item" /> </el-select> </el-form-item> </template>中表单验证controlok: [{ validator: checkPass, trigger: "blur" }],checkPass方法中怎么获取到该行数
时间: 2024-02-10 20:04:07 浏览: 129
可以通过传入参数的方式获取到该行数。在定义checkPass方法时,可以在参数中传入当前表单项的值和当前表单项的索引。例如:
```
checkPass(rule, value, callback, index) {
// index即为当前表单项的索引
// 可以根据索引来获取到该行数
const row = this.list[index];
// ...
}
```
在模板中调用该方法时,需要将当前表单项的索引作为参数传入:
```
<el-form-item
:prop="'list.' + scope.$index + '.controlok'"
:rules="fromDataRules.controlok"
>
<el-input
v-if="scope.row.controluse === 'S2F21'"
:disabled="
scope.row.iscontrol === false ||
scope.row.iscontrol == null ||
scope.row.iscontrol == ''
"
v-model="scope.row.controlok"
filterable
clearable
:class="{ 'is-invalid': errors['list.' + scope.$index + '.controlok'] }"
/>
<el-select
v-else
v-model="scope.row.controlok"
:disabled="
scope.row.iscontrol === false ||
scope.row.iscontrol == null ||
scope.row.iscontrol == ''
"
:placeholder="t('web_ems_tip_pleaseInput')"
filterable
clearable
:class="{ 'is-invalid': errors['list.' + scope.$index + '.controlok'] }"
>
<el-option
v-for="item in identifyingList"
:key="item.id"
:label="item"
:value="item"
/>
</el-select>
</el-form-item>
```
可以看到,在el-input和el-select中都有一个:class绑定,用来判断当前表单项是否验证通过,如果不通过,则添加一个is-invalid类名,可以在样式中对该类名进行样式设置。同时,在prop中也需要将当前表单项的索引作为属性名的一部分。这样,在定义checkPass方法时,就可以通过该属性名来获取到该行数的值。
阅读全文