Newer
Older
Nanping_sponge_GCGL / src / hooks / useAdaption.js
@liyingjing liyingjing on 25 Oct 2023 609 bytes 海绵工程管理
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
import { debounce } from '@/utils'

export default function useAdaption(proxy, dom, ispagination = true) {
  const offset = ispagination ? 30 :  0
  const maxHeight = ref(0)
  const onResize = debounce(function() {
    maxHeight.value = 0
    nextTick(() => {
      maxHeight.value = proxy.$refs[dom].offsetHeight - offset
    })
  }, 500)
  onMounted(() => {
    onResize()
  })
  window.addEventListener('resize', onResize)
  onUnmounted(() => {
    window.removeEventListener('resize', onResize)
  })

  return {
    maxHeight,
    onResize
  }
}