vue3 使用ref 获取 dom 元素的高度

前端 0

代码实现:

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

输出结果:

 

也许您对下面的内容还感兴趣: