Registering rolling events in VUE is no different from DOM

The following is used with the Keep-alive component

Mounted Registers rolling events

1
` this ` `. HandleScroll get scrollTop `

1
2
3
`mounted(){`
`window.addEventListener(“’scroll’“,` `this“.handleScroll); `
`} `

1
2
3
4
`handleScroll () {`
`let` `scrollTop = document.body.scrollTop; `
`this“.scroll = scrollTop; `
`} `

Called when the keep-alive component is activated. This hook is not called during server-side rendering.

1
2
3
4
5
6
7
`activated() {`
`if“(“this“.scroll > 0){`
`window.scrollTo(0,` `this“.scroll); `
`this“.scroll = 0; `
`window.addEventListener(“’scroll’“,` `this“.handleScroll); `
`} `
`} `

Called when the keep-alive component is disabled. This hook is not called during server-side rendering.

1
2
3
`deactivated(){`
`window.removeEventListener(“’scroll’“,` `this“.handleScroll); `
`} `