<el-form-item label="适用税率" prop="rate" :rules="[ { validator: (field, value, cb) => validateField(field, value, cb, '请输入数值范围为0-1的税率'), required: true, trigger: 'blur', }, ]" > > <el-input placeholder="请输入数值范围为0-1的税率" v-model="linkClientObj.rate" oninput="value=value.replace(/[^0-9.]/g,'')" ></el-input> </el-form-item>
方法:
// 校验税率的方法 methods:{ validateField(field, value, cb, message) { if (Number(value) > 1) { cb(new Error(message)); } if (value === "") { cb(new Error("请输入税率")); } }, }
标签:el,自定义,cb,校验,value,税率 From: https://www.cnblogs.com/qdyzhuang/p/16951908.html