vue3 は ref を使用して dom 要素の高さを取得します

コード:

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

出力結果:

 

おすすめ

転載: blog.csdn.net/qq_44694453/article/details/129030752