单个验证
handleSave(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
//dosomething
} else {
let anchor = this.$el.querySelector(".node-tab-01");//node-tab-01为锚点节点的类名
this.$nextTick(() => {
document.querySelector(".app-main").scrollTop = anchor.offsetTop-100; //.app-main为滚动容器的类名
});
return false;
return false;
}
});
}
}
多个验证
this.$refs[formName].validate((valid, dom) => {
if (valid) {
//do
} else {
for (let key of Object.keys(dom)) {
//获取ref dom 点进行锚点定位
let anchor = this.$refs[key].offsetTop;
this.$nextTick(() => {
document.querySelector(".app-main").scrollTop = anchor;
});
break;
}
return false;
}
});