How does vue register a global scrolling event to determine that the scrollbar executes after it scrolls to the bottom?

how does vue register a global scrolling event to determine that the scroll bar scrolls to the bottom and executes the event?

Mar.06,2021

ide/custom-directive.html" rel=" nofollow noreferrer "> learn about
you can customize a scroll instruction and do scroll judgment processing under this instruction method. On the
page, you only need v-custom instruction name =" method "


.

create listeners when a global component is created

    created() {
        window.addEventListener('scroll', this.doSomething);
    },
    destroyed() {
        window.removeEventListener('scroll', this.doSomething);
    }

you can listen to scrolling events in root vue, and then provide interfaces to other components to add listeners:

//  APP.vue  vue 
const onScrollListeners = []
//  this.$addOnScrollListener , $removeOnScrollListener
Vue.prototype.$addOnScrollListener = listener=> onScrollListeners.push(listener) 
Vue.prototype.$removeOnScrollListener =  listener=> onScrollListeners.splice(onScrollListeners.indexOf(listener)
window.onscroll = ()=> {
    if(xxxx){ // 
        onScrollListeners.forEach(listener=>listener())
    }
}

https://www.jianshu.com/p/47c.

Menu