获取 table 距离窗口上方的高度(有深度的文章)

简介: 获取 table 距离窗口上方的高度(有深度的文章)
import { ref, nextTick, computed, onBeforeUnmount } from 'vue'
export default function (tableRef, bottomHeight = '80px') {
  const topHeightVal = ref('400')
  nextTick(() => {
    topHeightVal.value = tableRef.value.$el.getBoundingClientRect().top
  })
  window.onresize = function () {
    topHeightVal.value = tableRef.value.$el.getBoundingClientRect().top
  }
  const topHeightValCom = computed(() => {
    return `calc(100vh - ${topHeightVal.value}px - ${bottomHeight})`
  })
  onBeforeUnmount(() => {
    window.onresize = undefined
  })
  return topHeightValCom
}


可手动设置高度


import { ref, nextTick, computed, onBeforeUnmount } from 'vue'
export default function (tableRef, bottomHeight = '80px') {
  const topHeightVal = ref('400')
  // 防止获取不到 top
  nextTick(() => {
    nextTick(() => {
      topHeightVal.value = tableRef.value.$el.getBoundingClientRect().top
    })
  })
  window.onresize = function () {
    topHeightVal.value = tableRef.value.$el.getBoundingClientRect().top
  }
  // 设置高度 (需要等待页面渲染完毕)
  function setTopHeight() {
    nextTick(() => {
      topHeightVal.value = tableRef.value.$el.getBoundingClientRect().top
    })
  }
  const topHeightValCom = computed(() => `calc(100vh - ${topHeightVal.value}px - ${bottomHeight})`)
  onBeforeUnmount(() => {
    window.onresize = undefined
  })
  return { topHeightValCom, setTopHeight }
}
目录
相关文章
|
4月前
|
人工智能 Ubuntu API
OpenClaw省钱部署指南:阿里云/本地部署+淘汰笔记本零成本打造24小时AI助理!
OpenClaw的爆火绝非偶然——它彻底打破了传统AI“只给建议不干活”的局限,实现了从“聊天顾问”到“数字员工”的范式转变,能自主执行文件处理、消息管理、网页自动化、定时任务等实际操作,成为个人与轻量团队的高效助手。但很多用户在部署时会陷入“高成本误区”,认为需要购置高价设备或订阅昂贵的大模型服务。
1560 3
修改elementui table 组件滚动条样式
修改elementui table 组件滚动条样式
340 0
|
8月前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
2383 59
Meta SAM3开源:让图像分割,听懂你的话
|
开发者 黑灰产治理
阿里云开发者社区积分细则
阿里云开发者社区,积分规则、领取、过期等相关说明
3586 18