1.示例组件结构

<template>
  <div ref="myBox">
    <v-page :ref="myPage">
    </v-page>
  </div>
</template>

 2.获取距离顶部的距离   

// ref=myBox元素
this.$refs.myBox.getBoundingClientRect().top
// ref=myPage组件
this.$refs.myPage.$el.getBoundingClientRect().top

  3.获取高度

// ref=myBox元素
this.$refs.myBox.offsetHeight
// ref=myPage组件
this.$refs.myPage.$el.offsetHeight

  4. 获取宽度

// ref=myBox元素
this.$refs.myBox.offsetWidth
// ref=myPage组件
this.$refs.myPage.$el.offsetWidth

 

未完待续..............

 

相关文章: