获取到顶部的距离

 
<template>
    <div ref="obtain"></div>
<template/>
<script>
 export default {
    data() {
        return {}
    },
    mounted() {
      // 滚动条的获取
      window.addEventListener('scroll', this.handleScrollx, true)
   },
    methods: {
        handleScrollx() {
          console.log('滚动高度', window.pageYOffset)
          console.log('距离顶部高度', this.$refs.obtain.getBoundingClientRect().top)
        }
    }
}
</ script>
原文地址:https://www.cnblogs.com/cyzbeke/p/13177285.html