js native class in how to control the height of the page vue, gets back to the bottom of the page and get the keyboard focus?

Use ref to create and specify the dom objects, use

  . this $ refs.xxx.scrollIntoView (); // make within the current element to scroll the browser window viewing area (xxx ref for the specified object name), 
  . the this $ refs.xxx.focus (); // administering a keyboard focus window,   the let curHeight = document.documentElement.scrollTop || document.body.scrollTop;
  document.documentElement.scrollTop = curHeight - 60;   document.body.scrollTop = curHeight - 60; // get the page height and the current page height reduction 60px;

  


dom DOM is defined in the standard way to access and manipulate HTML document,
The vue dom rendering is completed before Mounted (), and therefore, for the dom needs to be done in Mounted () therein;
      setTimeout(() => {
        this.$refs.commentBox.scrollIntoView();
        let curHeight = document.documentElement.scrollTop || document.body.scrollTop;
        document.documentElement.scrollTop = curHeight - 60;
        document.body.scrollTop = curHeight - 60;
        this.$refs.newComment.focus();
      }, 500);
 

  Use a timer to perform operations dom.

 

Guess you like

Origin www.cnblogs.com/lxj666/p/11345296.html