Comments (3)
自定义校验方法可以实现这种异步校验
不过你这个需求个人觉得应该放在网络请求层来做,response拦截器里判断该类错误的统一标志来校验更恰当。因为即使在输入的那一刻,异步校验的结果是正确的,等其它表单输入完后再提交至后端时依然有可能name已存在
,故这个校验不推荐放在表单校验层,因为结果不可靠
这个要求前后端协商一个统一的response结构,如:
{msg: '提交成功', data: xxx}
{errMsg: '该用户已存在', data: xxx}
from element-ui-verify.
我后端返回的格式是已经统一的
{msg: 提交失败,data: {name:已存在,age:年纪过大},类似这样,每个错误都有字段名和错误信息,想做成跟在提交表单控件相应位置下报错,更清晰点。
在拦截器里只能用message box ,
from element-ui-verify.
@zengcul
如果业务中大量存在这种异步校验需求可以自己拓展一个异步校验的规则
比如,规则名称可以为v-api
<el-form-item label="名称" prop="name" verify v-api="YourVerifyApi" field-change="clear">
<el-input v-model="model.name"></el-input>
</el-form-item>
具体实现再参考上面的文档结合根据你的业务来做吧
如果这类需求不是很多,依然可以使用自定义校验方法来做
from element-ui-verify.
Related Issues (20)
- el-select 和 el-input 校验形式不同 HOT 10
- 能否提供一份编译完的js HOT 2
- 引入后报错 ELEMENT is not defined HOT 2
- 应该增加maxLength的功能 用的也比较多 HOT 2
- 如何校验 日期,数组等数据类型? HOT 1
- alias 未生效 HOT 1
- 与element2.9.1版本冲突了么 HOT 2
- 默认校验规则 number异常 HOT 2
- 请问触发完所有校验时,如何focus第一个input控件 HOT 5
- 请问如何使用maxDecimalLength: 校验数字最大小数位 HOT 4
- 你好,请问这个校验不能兼容2.8.2以上的element ui的版本 HOT 1
- v1.2.0 typings 报错 HOT 3
- 关于multiple 自动触发非空校验 HOT 2
- 请问此插件现在支持ie吗,如果需要支持ie9以上需要做哪些? HOT 2
- 【BUG】ts编译后引用出错 exports is not defined HOT 2
- 可以改变默认的element-ui校验错误提示样式吗?使用冒泡方式提示错误 HOT 1
- alias设计不错,人性化,傻瓜化。。。 HOT 1
- 关于动态表单校验问题 HOT 1
- Element-UI 的表单校验,看来好多人都挺讨厌的
- 什么时候出vue3版本 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from element-ui-verify.