需求:带有滚动条的弹窗提交form时,滚动条滚动到form校验未通过的地方。
代码:
handleSubmit(name) {
this.$refs[name].validate((valid) => {
if (!valid) {
const srollHeight = [0, 100, 200, 300];
for (let i in this.$refs.formCustom.$children) {
if (this.$refs.formCustom.$children[i].validateState !== 'success') {
document.querySelector('.layhomework .ivu-modal-body').scrollTop = srollHeight[i];
break;
}
}
} else {
this.createHomework();
}
});
},