vue提交表单未通过表单验证,光标移动到第一个校验未通过的地方

这个问题是我在提交测试的时候,我们测试工程师提出了的bug,做了这么久第一次知道还有这效果,话不多说,上代码

 dataFormSubmit() {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                   //验证通过执行的操作 
                } else {
                    //验证不通过回滚到不通过的第一个位置
                    this.$nextTick(() => {
                        let isError = document.getElementsByClassName('is-error')
                        isError[0].scrollIntoView({
                            block: 'center',
                            behavior: 'smooth',
                        })
                    })
                }
            });
        },

看看效果:

回滚

猜你喜欢

转载自blog.csdn.net/qq_45061876/article/details/129146613