vue3通過ref獲取元素離頂部的距離
vue3版本 ^3.2.45
-
[ref].value.$el.getBoundingClientRect().top
- 通過ref獲取元素。
- 使用
getBoundingClientRect().top
獲取離頂部的距離
homeView.vue文章來源:http://www.zghlxwxcb.cn/news/detail-612009.html
<div ref="mTab" >........</div>
<script>
import { ref } from 'vue';
export default {
name: 'home',
setup() {
const mTab = ref(null)
//....
console.log(mTab.value.$el.getBoundingClientRect().top);
//.....
return {
mTab,
};
},
}
</script>
效果圖
文章來源地址http://www.zghlxwxcb.cn/news/detail-612009.html
到了這里,關于【Vue3】vue3通過ref獲取元素離頂部的距離的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!