<el-col :span="12">
<elian-table-form-item label="有效期" prop="checkSelfTime"
:rules="[
{
required: checkSelfAttShow,
validator: checkSelfTimeRequired,
trigger: 'blur'
}
]">
<elian-date-picker
name="checkSelfTime"
:start-time.sync="form.checkSelfBegnTime"
:end-time.sync="form.checkSelfEndTime">
</elian-date-picker>
</elian-table-form-item>
</el-col>
data() {
return {
checkSelfAttShow: false,
checkSelfTimeRequired:(rule, value, callback) => {
if (!this.form.checkSelfBegnTime && this.getCheckSelfAttShow()) {
callback(new Error('有效期开始日期必填'))
} else if (!this.form.checkSelfEndTime && this.getCheckSelfAttShow()) {
callback(new Error('有效期截止日期必填'))
} else {
callback()
}
},
}
}
<--form.checkSelfAtt是监听的数据,有值才下面有效期才必填-->
watch: {
'form.checkSelfAtt'(){
this.$nextTick(() =>{
this.checkSelfTimeShowChange()
})
},
},
methods: {
checkSelfTimeShowChange(){
this.checkSelfAttShow = this.form.checkSelfAtt?true:false
},
getCheckSelfAttShow(){
return this.checkSelfAttShow
},
}