正确方法:
javascript
this.$refs["myform"].clearValidate();
不要使用,因为它会清楚提示的同时把表单值还原为初始值
javascript
this.$refs["myform"].resetFields();
完整代码:
html
<a-form-model :model="myform" ref="myform" :rules="rules">
<a-form-model-item label="名称" prop="name">
<a-input v-model="myform.name"></a-input>
</a-form-model-item>
</a-form-model>
javascript
data() {
return {
myform: {
name: ''
},
rules:{
//表单验证
name: [{ required: true, message: '必填', trigger: 'blur' },
},
},
...
watch:{
myform: {
handler(newObj,oldObj){
if(newObj.name!=""){
this.$refs["myform"].clearValidate(); //清除所有校验规则
}
},
deep:true
}
},