vue3 uses ref to get the height of the dom element

Code:

<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>

Output result:

 

Guess you like

Origin blog.csdn.net/qq_44694453/article/details/129030752