代码实现:
<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>
输出结果: