点击保存校验 报错项class会出现 is-error,利用它实现滚动到报错位置,
使用scrollIntoView ,配置 { behavior: “smooth”, block: “center” }
<el-form :rules="rules" ref="dataRef">
<el-button @click="save()">保存</el-button>
</el-form>
this.$refs["daRef"].validate((valid) => {
if (valid) {
// 校验通过
} else {
this.$nextTick(() => {
const el= this.$refs.dataRef.$el;
const error = formEl.querySelector(".is-error");
if (error ) {
error .scrollIntoView({ behavior: "smooth", block: "center" });
}
});
return false;
}
});