1.表单添加两个框,prop写上
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" >
<el-form-item type="type" label="时间" prop="dateSectOne">
<div class="timeShijian">
<el-time-picker :clearable="false" v-model="ruleForm.dateSectOne.first" placeholder="开始时间" value-format="HH:mm" format="HH:mm"></el-time-picker>
<el-time-picker :clearable="false" v-model="ruleForm.dateSectOne.second" value-format="HH:mm" placeholder="结束时间" format="HH:mm"></el-time-picker>
</div>
</el-form-item>
</<el-form >
2.data里写,验证规则添加validator: this.validateFields文章来源:https://www.toymoban.com/news/detail-683189.html
ruleForm: {
dateSectOne:{first:'',second:'',},
},
rules: {
dateSectOne: [
{validator: this.validateFields, required: true, message: '请选择班次时间'},
],
}
3.validateFields设置文章来源地址https://www.toymoban.com/news/detail-683189.html
validateFields(rule, value, callback) {
// 在这里编写验证逻辑
if (value.second && value.first) {
callback();
} else {
callback(new Error('请选择时间'));
}
},
到了这里,关于el-form表单el-form-item prop一次验证两个值的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!