antd 表单 校验名字重复
好记性不如烂笔头,所以就记下啦~
function inputNameRepeat(): Rule { return { validator: async (rule: RuleObject, value: string) => { if (value === initValue.name) { return; } setValidateStatus('validating'); const res: any = await validateName({ name: value }); if (!value) { setValidateStatus('error'); return Promise.reject('请输入*****'); } if (!res.success) { setValidateStatus('error'); return Promise.reject('名字重复,请重新输入'); } setValidateStatus('success'); return Promise.resolve(); }, validateTrigger: 'onBlur' }; }
over:就是这样 喵~ 哈哈哈