日常的工作中,在对整个页面的表单进行数据校验的时候,页面自动滚动到页面的第一个错误处。
//滚动到第一个错误处
export function goFirstError() {
setTimeout(() => {
let isError = document.getElementsByClassName("el-form-item__error");
isError[0].scrollIntoView({
// 滚动到指定节点
// 值有start,center,end,nearest,当前显示在视图区域中间
block: "center",
// 值有auto,smooth,缓动动画(当前是慢速的)
behavior: "smooth",
});
}, 100);
}