滚动到VueJs中的无效输入

Nom*_*omi 0 vue.js

我有什么办法可以使用VueJs滚动到具有无效类的第一个输入。现在我正在使用window.scrollTo(500, 0);这显然不是适当的解决方案。

Ada*_*lor 5

您可能需要使用Vue.nextTick等待Vue在需要应用无效类的任何地方应用无效类。

this.$nextTick(() => {
  let domRect = document.querySelector('.error').getBoundingClientRect();
  window.scrollTo(
    domRect.left + document.documentElement.scrollLeft,
    domRect.top + document.documentElement.scrollTop
  );
});
Run Code Online (Sandbox Code Playgroud)