Giter Site home page Giter Site logo

Comments (3)

aweiu avatar aweiu commented on August 22, 2024

自定义校验方法可以实现这种异步校验

不过你这个需求个人觉得应该放在网络请求层来做,response拦截器里判断该类错误的统一标志来校验更恰当。因为即使在输入的那一刻,异步校验的结果是正确的,等其它表单输入完后再提交至后端时依然有可能name已存在,故这个校验不推荐放在表单校验层,因为结果不可靠

这个要求前后端协商一个统一的response结构,如:

{msg: '提交成功', data: xxx}
{errMsg: '该用户已存在', data: xxx}

from element-ui-verify.

zengcul avatar zengcul commented on August 22, 2024

我后端返回的格式是已经统一的
{msg: 提交失败,data: {name:已存在,age:年纪过大},类似这样,每个错误都有字段名和错误信息,想做成跟在提交表单控件相应位置下报错,更清晰点。
在拦截器里只能用message box ,

from element-ui-verify.

aweiu avatar aweiu commented on August 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.