/*
 * @Author       : ldc 951052117@qq.com
 * @Date         : 2023-06-13 10:40:41
 * @LastEditors  : ldc 951052117@qq.com
 * @LastEditTime : 2023-06-13 10:40:45
 * @Description  : table尺寸 Resize
 */
import { onMounted, onUnmounted, ref } from 'vue'

//导出hooks函数
const useTableResize = (width = 0) => {
  const w = ref('')
  //计算宽度函数
  const calcTableWidth = () => {
    w.value = document.body.clientWidth - 280 - width
  }
  //挂载后
  onMounted(() => {
    //初始化计算一次
    calcTableWidth()
    //resisze计算
    window.addEventListener('resize', calcTableWidth)
  })
  //销毁后
  onUnmounted(() => {
    window.removeEventListener('resize', calcTableWidth)
  })

  //导出外面要用的响应式数据
  return {
    w,
  }
}
export default useTableResize
