表单:
<el-form-item label="周期间隔(天)" prop="periodSpace" v-if="isServicePeriod">
<el-input v-model="form.periodSpace" type="number" placeholder="请输入周期间隔(天)" />
</el-form-item>
data:
// 校验规则
let validatorPeriodSpace = (rule, value, callback) => {
if(this.isServicePeriod){
if (!value) return callback(new Error('周期间隔不能为空'))
}
callback();
};
定义变量:
isServicePeriod: true,
rules:
periodSpace: [
// { required: true, message: "测试周期不能为空", trigger: "change" }
{ required: true, trigger: 'blur', validator: validatorPeriodSpace }
],
表单中更改项:
<el-form-item label="测试周期" prop="period">
<el-select v-model="form.period" placeholder="请选择测试周期" @change="changeService">
<el-option
v-for="dict in periodOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
></el-option>
</el-select>
</el-form-item>
changeService(value){
if(value == 1 || value == 0){
this.isServicePeriod = false
}else{
this.isServicePeriod = true
}
},
reset()方法中:
this.isServicePeriod = true
标签:vue,isServicePeriod,value,element,callback,dict,表单,true From: https://www.cnblogs.com/cw828/p/17658419.html