博客
关于我
ElementUI表单校验的validate方法返回参数始终为true的问题
阅读量:377 次
发布时间:2019-03-05

本文共 452 字,大约阅读时间需要 1 分钟。

问题描述

按照官方例子调用validate方法:

在这里插入图片描述

this.$refs.registerForm.validate((valid) => {           console.log(valid)        if (valid) {             // this.registerNext = true        } else {             return false        }      })

发现不管表单中内容是否检验通过,valid参数的值始终为true

原因及解决方法

通过查阅文档发现出现这个问题的原因是对于同一个校验规则rules,我同时在多个同名表单(即ref名相同)中使用了该规则。虽然rules能够对每个el-form里的表单进行校验,但返回回来的valid只代表最后一个el-form的状态。

因此解决方案即为将用了同一rules的多个表单的ref属性命名为不同的即可,在调用validate校验时,只会校验该表单下的属性是否符合相应的规则。

转载地址:http://lomg.baihongyu.com/

你可能感兴趣的文章
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>