关于elementui form表单过长,看不到未填项

关于form表单过长,点击确定找到未填项并定位到此处

上代码,自辩,我是好使滴

    heightToTop(ele){
      let root = document.body;
      let height=0;
      do{
        height+=ele.offsetTop;
        ele = ele.offsetParent;
      }while(ele!==root)
      return height;
    },
    eleScrollError(){
      this.$nextTick(()=>{
        let isError=document.getElementsByClassName('is-error');
        console.log(isError);
        // document.querySelector(".main2").scrollTo({behavior:"smooth",top:this.heightToTop(isError[0]) - 60},500);
        let container = isError[0].querySelector("input")||isError[0].querySelector("textarea");
        container.focus();
      })
    },

  //以下没试,自辩
    scrollError(DOM){
      this.$nextTick(()=>{
        let container = document.querySelector(".main2");
       container.scrollTo({behavior:"smooth",top:this.$refs[DOM].offsetTop},500);
      })
    },        

 

参考:https://blog.csdn.net/q140948940/article/details/115520524

posted @ 2021-09-16 17:42  钱小柒  阅读(514)  评论(0编辑  收藏  举报