vue el-form 自定义校验规则

<el-form-item class='fzfp' label='分值分配:' prop='fzfp'>
<div v-if='preview'>{{ this.rowData.socreOptionValue }}</div>
<div v-else>
<el-row class='fzfp_row'>
<el-input v-model='socre_option.A[0]' placeholder=''>
<template slot='prepend'>A:</template>
</el-input>
<el-input v-model='socre_option.B[0]' placeholder=''>
<template slot='prepend'>B:</template>
</el-input>
<el-input v-model='socre_option.C[0]' placeholder=''>
<template slot='prepend'>C:</template>
</el-input>
<el-input v-model='socre_option.D[0]' placeholder=''>
<template slot='prepend'>D:</template>
</el-input>
<el-input v-model='socre_option.E[0]' placeholder=''>
<template slot='prepend'>E:</template>
</el-input>
</el-row>
</div>
</el-form-item>


fzfp: [{ required: true, validator: (rules, value, callback) => { // let { valueA, valueB, valueC, valueD, valueE } = this.form let valueA = this.socre_option.A[0] let valueB = this.socre_option.B[0] let valueC = this.socre_option.C[0] let valueD = this.socre_option.D[0] let valueE = this.socre_option.E[0] let reg = new RegExp(/^([1-9]\d*|0)(\.\d{1,2})?$/)//正则校验 if (valueA === '' || valueB === '' || valueC === '' || valueD === '' || valueE === '') { console.log(valueA, valueB, valueC, valueD, valueE) return callback(new Error('请输入分值')) } else if (!reg.test(valueA) || !reg.test(valueB) || !reg.test(valueC) || !reg.test(valueD) || !reg.test(valueE)) { return callback(new Error('请输入数字')) } return callback() } }],

  

posted @ 2021-10-28 10:06  闰土的土  阅读(799)  评论(0编辑  收藏  举报