当前位置:   article > 正文

Vue取消表单校验提示的方法_vue3.2 关闭表单取消验证

vue3.2 关闭表单取消验证

正确方法: 

this.$refs["myform"].clearValidate();

不要使用,因为它会清楚提示的同时把表单值还原为初始值

this.$refs["myform"].resetFields();

完整代码:

  1. <a-form-model :model="myform" ref="myform" :rules="rules">
  2. <a-form-model-item label="名称" prop="name">
  3. <a-input v-model="myform.name"></a-input>
  4. </a-form-model-item>
  5. </a-form-model>
  1. data() {
  2. return {
  3. myform: {
  4. name: ''
  5. },
  6. rules:{
  7. //表单验证
  8. name: [{ required: true, message: '必填', trigger: 'blur' },
  9. },
  10. },
  11. ...
  12. watch:{
  13. myform: {
  14. handler(newObj,oldObj){
  15. if(newObj.name!=""){
  16. this.$refs["myform"].clearValidate(); //清除所有校验规则
  17. }
  18. },
  19. deep:true
  20. }
  21. },

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/438381
推荐阅读
相关标签
  

闽ICP备14008679号