Files
pqs-9100_client/frontend/src/hooks/useViewSize.ts

37 lines
873 B
TypeScript
Raw Normal View History

2024-10-28 13:25:45 +08:00
import { ref } from 'vue'
export const useViewSize = () => {
const popupBaseView = ref(null)
const viewWidth = ref("0")
const viewHeight = ref("0")
const unit = 'px'
/**
*
*/
const updateDimensions = () => {
if (popupBaseView.value) {
viewWidth.value = popupBaseView.value.offsetWidth + unit
viewHeight.value = popupBaseView.value.offsetHeight + unit
}
}
/**
*
*/
onMounted(() => {
updateDimensions()
window.addEventListener('resize', updateDimensions)
})
/**
*
*/
onUpdated(() => {
updateDimensions()
})
return { popupBaseView, viewWidth, viewHeight }
}