当我点击退回的时候会提示要填写审核意见,当点击通过时可以不填写意见,动态表单验证
<el-form :model="formData" ref="form">
<el-form-item class="check" label="审核:" prop="textarea" :rules="checked == 1 ? [{ required:false}] : [{ required:true,message:'审核意见不能为空'}]">
<el-input
type="textarea"
:rows="2"
placeholder="请输入审核意见"
v-model="formData.textarea"
:autosize="{ minRows: 6, maxRows: 15}"
>
</el-input>
</el-form-item>
</el-form>
data(){
return {
checked:1,
}
}
methods:{
async backClose() {
this.checked = 0;
await this.$nextTick();
try {
const valid = await this.$refs.form.validate();
if (valid) {
Api.check({
checkId: this.info.id,
checkOpinion: this.textarea,
checkResult: 3,
}).then((response) => {
this.close();
if (response.code === 0) {
this.$message({
message: "提交成功",
type: "success",
});
this.refresh();
} else {
this.$message({
message: response.msg,
type: "warning",
});
}
});
}
} catch {}
}
watch:{
dialogVisible: {
handler (value) {
if(value === true){
this.getSubList();
this.checked = 1; //这句代码只会清理*星号,不会清理提示语
} else {
this.$nextTick(() => {
this.$refs.form?.clearValidate();
});
}
},
},
},
在监听时加上$nextTick()在重新打开一条审核记录的时候执行操作,使用clearValiate()就可以清除表单的提示语了