antd-form表单定位到第一个校验失败的地方
代码如下
const value = form.validateFields();
value.then(resParams => {
// 校验通过代码
}).catch(() => {
// 在catch中进行错误定位
const errorList = (document as any).querySelectorAll(".ant-form-item-has-error");
errorList[0]?.scrollIntoView({
block: "center",
behavior: "smooth",
});
})
原理
antd-form表单,会在校验过程中给校验不通过的item增加“ant-form-item-has-error”类,我们只需要找到第一个item,对其进行定位即可

浙公网安备 33010602011771号