1.方法一
(最简单有效的)
<el-form ref="newForm" ...>
</el-form>
//在js方法中校验
this.$refs.newForm.validate(valid => {
if (valid) {
// 验证通过
} else {
this.$nextTick(() => {
let isError = document.getElementsByClassName('is-error')
isError[0].scrollIntoView({
// 滚动到指定节点
// 值有start,center,end,nearest,当前显示在视图区域中间
block: 'center',
// 值有auto、instant,smooth,缓动动画(当前是慢速的)
behavior: 'smooth',
})
})
return
}
})
2.方法2
给各el-form-item设置ref,然后使用$el.scrollIntoView()进行滚动
(由于表单内容实在过多,故尽量不选择该方法)