javascript - remote legality verification problem of input box value in form
仅有的幸福
仅有的幸福 2017-07-05 11:04:40
0
2
900

1. The problem is this. There is an input box. I want to verify whether the value already exists in the database at the onBlur moment. Just like when we usually register an email, we will be prompted in real time whether the email name has been used. Previously, in the jquery era, ajax requests could be referred to as synchronous. However, in the antd dva framework, requests are initiated through dispatch. How to implement this in this case?

仅有的幸福
仅有的幸福

reply all(2)
给我你的怀抱

You may not fully understand some concepts related to Redux.

What dispatch initiates is not a request, but an Action that changes the global state. However, the most common scenario for changing data status Action is [sending asynchronous network requests]. This does not mean that the request must be dispatched, nor does it mean that dispatch must be used in asynchronous scenarios.

Specific to your question, the state of an input box is obviously very local, and obviously [under normal circumstances] is not coupled with the state of other parts of the page. So at this time, you can completely abandon the Redux package encapsulated by Dva, and instead encapsulate a module based on fetch / axios / $.ajax to provide you with this input box component.

Finally, synchronous Ajax is a bad practice. It is recommended to encapsulate asynchronous requests as Promise.

黄舟

@ewind’s correct reply
In fact, the reason why I have always been confused before is that I didn’t know that the validateFields method of the form component of the antd framework will automatically block asynchronous operations. I always thought that the asynchronous verification did not return the form that had been submitted before.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!