// 自动触发
mounted: function () {
window.addEventListener("scroll", this.handleScroll, true);
},
// 页面销毁前
beforeDestroy: function () {
window.removeEventListener("scroll", this.handleScroll);
},
// 获取滚动条的滚动距离
handleScroll() {
console.log(this.$refs.scorll_top.getBoundingClientRect().top);
},
注意这里:ref一定要写在div上,写在组件上面会报错