Asynchronous request verification
Attention: asyncValidator is only supported in 1.11.0, and my conclusion below is that I used the 1.8.0 version myself, so it failed. Please know! !
Refer to the github project:async-validator
// PROMISE USAGE ({ name: "muji", asyncValidator: (rule, value) => ('/nameValidator', { name: value }), }, (errors, fields) => { if(errors) { // validation failed, errors is an array of all errors // fields is an object keyed by field name with an array of // errors per field return handleErrors(errors, fields); } // validation passed }) .then(() => { // validation passed }) .catch(({ errors, fields }) => { return handleErrors(errors, fields); })
As mentioned above, in readme, I always said that I used asyncValidator, so I always thought that I would receive asyncValidator as a keyword, but after trying for a long time, it just didn't work. In fact, just use the validator keyword. Just use it as follows...
Usage definition
validatorFieldRule: [ { required:true, validator: checkEmpty, trigger: "change"} ]
Verification rule definition
var checkEmpty= (rule, value, callback) => { ('/api/file').then( res => { callback(); }) .catch( err => { callback(err); }) };
This is the article about the use of async-validator asynchronous request verification in element. For more related element async-validator asynchronous request verification content, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!