How do you click paging to get vue back to the top?

online search can use document.body.scrollTop, but I wrote a test in the project demo has no effect, why?

   
   
   <button @click="opt"></button>
   
    opt(){
       if(document.body.scrollTop){
         document.body.scrollTop = 0
       }else {
         document.documentElement.scrollTop = 0
       }
     },
Sep.07,2021

indicates that the scrolling container is not scrollTop of window or body, modified scrolling container


window.scrollTo (0L0)


is the demo of the subject in the autoScroll container? If so, no, otherwise the answer upstairs should be OK


print document.body.scrollTop if 0 means the scrolling container is not body, and see if there is a parent container overflow-y is auto | scroll , put its scrollTop=0

Menu