vue 表单验证滚动条滚动到指定表单位置

1 多个表单的情况

scrollView(object,formname) {
for (const i in object) {
let dom = this.$refs[formname]
// 这里是针对遍历的情况(多个输入框),取值为数组
if (Object.prototype.toString.call(dom) !== '[object Object]') {
dom = dom[0]
}
// 第一种方法(包含动画效果)
dom.$el.scrollIntoView({ // 滚动到指定节点
// 值有start,center,end,nearest,当前显示在视图区域中间
block: 'start',
// 值有auto、instant,smooth,缓动动画(当前是慢速的)
behavior: 'smooth'
})
break // 因为我们只需要检测一项,所以就可以跳出循环了
}
},

2 单个表单的情况

scrollView(object) {
for (const i in object) {
let dom = this.$refs
// 这里是针对遍历的情况(多个输入框),取值为数组
if (Object.prototype.toString.call(dom) !== '[object Object]') {
dom = dom[0]
}
// 第一种方法(包含动画效果)
dom.$el.scrollIntoView({ // 滚动到指定节点
// 值有start,center,end,nearest,当前显示在视图区域中间
block: 'start',
// 值有auto、instant,smooth,缓动动画(当前是慢速的)
behavior: 'smooth'
})
break // 因为我们只需要检测一项,所以就可以跳出循环了
}
},

posted @ 2021-03-08 16:07  蓝色闪电-狂奔  阅读(712)  评论(0编辑  收藏  举报