表单验证出错后,如何定位到出错处呢?
- this.$refs.['elForm'].validate(valid => {
-
- if(!valid){
- this.$nextTick(()=>{
- const errorDiv = document.getElementsByClassName('has-error')
- errorDiv[0].scrollIntoView({ behavior: "smooth", block: "center" })
- })
-
- }{
- ....
- }
- })
其中,scrollIntoView的参数:
block: "center", // 显示在视图区域:值有start, center, end,nearest
behavior: "smooth", // 动画:值有auto、instant, smooth