【问题标题】:How to solve Validation error after submit提交后如何解决验证错误
【发布时间】:2019-11-14 07:34:51
【问题描述】:

我对表单中的每个输入都使用 veevalidate 规则。使用有效数据提交后,所有这些数据都已成功发送到后端,但在前端每个输入都突出显示为有效。

我在 veevalidate 中添加了重置方法,以便在选择提交时取消设置任何错误。但它不起作用。这是我的代码的一部分

       beforeSubmit() {
       this.$validator.pause();
       this.$nextTick(() => {
          this.$validator.errors.clear();
          this.$validator.fields.items.forEach(field => 
           field.reset());
          this.$validator.fields.items.forEach(field => 
          this.errors.remove(field));
          this.$validator.resume();
           });

          this.$validator.validateAll().then((result) => {
              this.onSubmit();
              ...

【问题讨论】:

    标签: vue.js nuxt.js vee-validate


    【解决方案1】:

    我想到了解决方案:当所有错误都从下一次渲染中的表单中删除时,我们应该用 this.$validator.reset() 替换 this.$validator.resume() 方法。就这样。 一般来说,工作部分是

    beforeSubmit() {
       this.$validator.pause();
       this.$nextTick(() => {
              this.$validator.errors.clear();
              this.$validator.fields.items.forEach(field => 
               field.reset());
              this.$validator.fields.items.forEach(field => 
              this.errors.remove(field));
              this.$validator.reset();
               });
    
              this.$validator.validateAll().then((result) => {
                  this.onSubmit();
                  ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 2015-07-25
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      相关资源
      最近更新 更多