核心代码

<template>
    <div ref="obtain"></div>
<template/>
 
<script>
export default {
    data() {
        return {
        	screenHeight: document.body.clientHeight // 获取页面高度
        }
    },
    mounted() {
      // 滚动条的获取
      window.addEventListener('scroll', this.handleScrollx, true)
   },
    methods: {
        handleScrollx() {
          console.log('滚动高度', window.pageYOffset)
          console.log('距离顶部高度', this.$refs.obtain.getBoundingClientRect().top)
        }
    }
}
</ script>
Logo

前往低代码交流专区

更多推荐