直接上代码解决方式很简单直接上代码
//在js方法中校验
this.$refs.formRef.validate(valid => {
if (!valid) {
this.$nextTick(() => {
let isError = document.getElementsByClassName('is-error')
isError[0].scrollIntoView({
// 滚动到指定节点
// 值有start,center,end,nearest,当前显示在视图区域中间
block: 'center',
// 值有auto、instant,smooth,缓动动画(当前是慢速的)
behavior: 'smooth',
})
})
return false
}
})
参考文章: https://blog.csdn.net/weixin_38345306/article/details/130822587