vue 上拉加载几行代码搞定(pc + 移动端)

created () {
    window.addEventListener('scroll', this.onScroll)
},

    methods: {
        onScroll () {
        let innerHeight = document.querySelector('#app').clientHeight
        let outerHeight = document.documentElement.clientHeight
        let scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop
        // 页面高度 = 屏幕高度 + 滑动高度
        if (innerHeight === (outerHeight + scrollTop)) {
            console.log(" 已到底部")
        }
        }
    }
posted @ 2021-04-22 09:54  libenzheng  阅读(475)  评论(0)    收藏  举报