Element form validation of a single input input box (out of the form), add validation

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.
Insert picture description here

In the Online search a lot of ways, there is no suitable, so he used the official of Form-Itemthe property error
Insert picture description here
Note: with errorit, you do not need to el-form-itemadd propand rules, and directly el-form-itemadd 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:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45846359/article/details/114694598