代碼實(shí)現(xiàn):
<template>
<div ref="mains" class="search"></div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
const mains = ref()
onMounted(() => {
const height = mains.value.clientHeight
console.log(height, 1234)
})
</script>
<style scoped lang="less">
.search {
width: 100px;
height: 100px;
margin: 0 auto;
background-color: greenyellow;
}
</style>
輸出結(jié)果:
文章來源:http://www.zghlxwxcb.cn/news/detail-590871.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-590871.html
到了這里,關(guān)于vue3 使用ref 獲取 dom 元素的高度的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!