小工具知识网

当前位置: 首页 > 行业知识 > vue3 使用ref 获取 dom 元素的高度

行业知识

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

2026-11-13 21:45:00 来源:互联网转载

代码实现:

  import { ref, onMounted } from 'vue'const mains = ref()onMounted(() => {  const height = mains.value.clientHeight  console.log(height, 1234)}).search {  width: 100px;  height: 100px;  margin: 0 auto;  background-color: greenyellow;}

输出结果:

 

上一篇:如何设置nicescroll背景宽度?详细步骤教程,轻松搞定!

下一篇:数仓之【MaxCompute】