The project requirement is that the denomination to be entered cannot be greater than the original price. It is obviously impossible to check the value of the last piece of data due to each cycle.
In the Online search a lot of ways, there is no suitable, so he used the official of Form-Item
the property error
Note: with error
it, you do not need to el-form-item
add prop
and rules
, and directly el-form-item
add the label :error="scope.row.error"
to
Code:
<el-table-column label="优惠面额(元)">
<template slot-scope="scope">
<el-form-item :error="scope.row.error">
<el-input v-model.number="scope.row.parValue" @input="tableParValueChange(scope.row)" />
</el-form-item>
</template>
</el-table-column>
// 表格中优惠面额校验
tableParValueChange(row) {
if (row.parValue === '') {
row.error = '不能为空'
} else if (row.parValue < 1) {
row.error = '优惠面额最小为1'
} else if (row.parValue > row.salePrice) {
row.error = '不能大于' + row.salePrice
} else {
row.error = ''
}
},
final effect: